在Python中查找字符串的示例 [英] Examples for string find in Python
本文介绍了在Python中查找字符串的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
可以使用 str.index
也是:
>>> ; 'sdfasdf'.index('cc')
Traceback(最近一次调用的最后一个):
在< module>中的第1行中输入< pyshell#144>
'sdfasdf'.index('cc')
ValueError:找不到子字符串
>>> 'sdfasdf'.index('df')
1
I am trying to find some examples but no luck. Does anyone know of some examples on the net? I would like to know what it returns when it can't find, and how to specify from start to end, which I guess is going to be 0, -1.
解决方案
you can use str.index
too:
>>> 'sdfasdf'.index('cc')
Traceback (most recent call last):
File "<pyshell#144>", line 1, in <module>
'sdfasdf'.index('cc')
ValueError: substring not found
>>> 'sdfasdf'.index('df')
1
这篇关于在Python中查找字符串的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文