首页 > 编程语言 > 详细

python find和index的区别

时间:2019-07-31 00:10:46      阅读:254      评论:0      收藏:0      [点我收藏+]

 

如果找不到目标元素,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
>>> 

 

参考:

https://blog.csdn.net/yolandera/article/details/80264876

 

 

python find和index的区别

原文:https://www.cnblogs.com/sea-stream/p/11273317.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!