![3d0ef9de6efc33c1f459545b913c3ad3.png](https://i-blog.csdnimg.cn/blog_migrate/d58d2e842ed3be39bf2e35b140261f27.jpeg)
# 字符串的查找和替换
hello_str="hello python"
# 1.判断是否以知道字符串开始
print(hello_str.startswith("he"))
# 2.判断是否以指定字符串结束
print(hello_str.endswith("on"))
# 3.查找指定字符串
print(hello_str.find("llo"))
# index同样可以查找指定字符串在大字符串中的索引
# index指定的字符串不存在会报错,find指定的字符串不存在不会报错
print(hello_str.find("abc"))
# print(hello_str.index("abc"))
# 4.替换字符串
# replace方法执行完成之后,会返回一个新的字符串
# 注意:但是不会修改原有的字符串的内容
a=hello_str.replace("python","java")
print(hello_str)
print(a)