python find和index的区别
如果找不到目标元素,index会报错,find会返回-1
>>> s="hello world"
>>> s.find("llo")
2
>>> s.index("llo")
2
>>> s.index("llos")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found
>>> s.find("llos")
-1
>>>