字符串查找方法——find()

find()方法查找子字符串,若找到返回下标值,找不到返回-1。

find()方法语法:

str.find(str, beg=0, end=len(string))#str---需要索引的字符串;beg -- 开始索引,默认为0;end -- 结束索引,默认为字符串的长度

 例如:

>>> str1="abcdabcdcc"
>>> str1.find("abc")
0
>>> str1.find("abc",2)
4
>>> str1.find("abc",2,5)
-1
>>> str1.find("abc",2,8)
4