sh_17_字符串的查找和替换
2024-09-01 10:51:52
sh_17_字符串的查找和替换
hello_str = "hello world" # 1. 判断是否以指定字符串开始
print(hello_str.startswith("Hello")) # 2. 判断是否以指定字符串结束
print(hello_str.endswith("world")) # 3. 查找指定字符串
# index同样可以查找指定的字符串在大字符串中的索引
print(hello_str.find("llo"))
# index如果指定的字符串不存在,会报错
# find如果指定的字符串不存在,会返回-1
print(hello_str.find("abc")) # 4. 替换字符串
# replace方法执行完成之后,会返回一个新的字符串
# 注意:不会修改原有字符串的内容
print(hello_str.replace("world", "python")) print(hello_str)
最新文章
- iOS静态库开发中对Bitcode的支持
- PHP 判断点是否在多边形内
- asp.net c#过滤html代码,净化DIV SPAN等
- android 屏幕旋转
- 使用C#和.NET的原因
- Fast and Robust Hand Tracking Using Detection-Guided Optimization
- Java基础之在窗口中绘图——显示曲线的控制点(CurveApplet 2 displaying control points)
- K650D安装黑苹果
- Reference in the manifest does not match the identity of the downloaded assembly
- ios越狱开发第一次尝试记录
- 迷途指针 new delete
- QT内置的ICON资源
- acdream 1211 Reactor Cooling 【边界网络流量 + 输出流量】
- web从入门开始(5)-----表单
- 关于SPI通信原理与程序实现
- jQuery -- 光阴似箭(四):jQuery 遍历
- 【DWM1000】 code 解密3一ANCHOR RUN起来
- 力扣(LeetCode)832. 翻转图像
- “2017面向对象程序设计(Java)第十三周学习总结”存在问题的反馈及本周教学安排
- NodeJS+Express开发web,为什么中文显示为乱码