mystr = "hello world hello farsight hello cpdd"
1. 查询统计家族 find rfind index rindex count
find:
在原字符串中查找子字符串
返回值:子字符串在原字符串中的起始位置。如果查找不到返回-1
rfind:
从右向左在原字符串中查找子字符串
返回值:子字符串在原字符串中的起始位置。如果查找不到返回-1
demo:
result = mystr.find("world1")
print(result)
name = "hello.hello.txt"
pos = name.rfind(".")
print(name[:pos])
index:
在原字符串中查找子字符串的内容
查找到:返回下标, 查找不到会进行报错
rindex:
从右往左查找
查找到:返回下标, 查找不到: 报错
demo:
result = mystr.i