string的方法find

Posted lcfzh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于string的方法find的主要内容,如果未能解决你的问题,请参考以下文章