jeapedu 36 字符串函数find

链接: 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值