python中find和index的区别find 和 index 都是⽤来搜索⽬标字符串的位置
区别:
如果⽬标字母不存在,find 返回 -1,index 返回异常
a='sdfdjfjofe'
a.find("d")
1
a.index("d")
1
a.find("x")
-1
a.index("x")
Traceback (most recent call last):
File "<input>", line 1, in <module>
python index函数
ValueError: substring not found