string的方法find

官方解释:find(sub[, start[, end]]) Return the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found.(返回在切片s [start:end]中找到substring sub的字符串中的最低索引。可选参数start和end被解释为切片表示法。如果未找到sub,则返回-1。)

In [142]: print(s13.find('skyler')) # 查找a出现的位置
2

In [143]: print(s13.find('walter')) # 查找Walter的位置,如果没有则返回-1
-1

In [144]: print(s13.find('a', 8, 22)) # 切片找
20
原文地址:https://www.cnblogs.com/lcfzh/p/10034453.html