链接: https://pan.baidu.com/s/1mjYJ0zY 密码: feix
print(help(str.find))
print(help(str.rfind))
sub = "11aa22cc33aa44"
# 01234567890123
print(sub.find("aa"))
print(sub.rfind("aa"))
print(sub.find("aa", 3))
print(sub.rfind("aa", 11))
#find(...)
# S.find(sub[, start[, end]]) -> int
# if start end, find sub in s[start,end]
print(help(str.count))
s = "eehello jeeeedu.com " * 4
sub = "ee"
print(s)
pos = 0
count = 0
while s.find(sub, pos) != -1: # 当前一个sub找到,从pos之后的s里还有sub的话:
pos = s.find(sub, pos) # 从0开始查找,返回位置
print(count, pos)
count += 1
pos += len(sub) # 下一次跨过pos + sub长度
s = "eehello jeeeedu.com " * 4
sub = "ee"
print(s)
i = 0
pos = 0
while i < s.count(sub): # 循环次数小于出现次数
pos = s.find(sub, pos) # 从0开始查找,返回位置
print(i, pos)
pos += len(sub) # 下一次跨过pos + sub长度
i += 1