Python字符串二
hello_str = "hello python"
字符串是否以指定字符串开头
startswitch方法
print(hello_str.startswith("he"))
字符串是否以指定字符串结尾
endswitch方法
print(hello_str.endswith("on"))
查找指定字符串
index和find
index指定的字符串不存在会报错
print(hello_str.index("l"))
find指定的字符串不存在会返回-1
print(hello_str.find("w"))
字符串的替换
replace方法不会修改原有字符串的值
hello_str1 = hello_str.replace("python","world")
print(hello_str1)
print(hello_str.replace("python","world"))
print(hello_str)