3、使用index()和rindex():
>>> str = "this is really a string example....wow!!!"
>>> substr = "is"
>>> print(str.index(substr))
2
>>> print(str.rindex(substr))
5
>>> print(str.rindex('123'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found
>>> print(str.index('123'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found
index()和rindex()
find()和rfind()
类似,不同点在于,index()和rindex()找不到子字符串后,会返回ValueError