python find()函数


实例(Python 2.0+)

 str1 = "this is string example....wow!!!";
str2 = "exam";
print str1.find(str2);
print str1.find(str2, 10);
print str1.find(str2, 40);

以上实例输出结果如下:

15 15 -1

实例(Python 2.0+)

>>>info = 'abca'
print info.find('a') # 从下标0开始,查找在字符串里第一个出现的子串,返回结果:0 0
>>> print info.find('a',1) # 从下标1开始,查找在字符串里第一个出现的子串:
返回结果3 3
>>> print info.find('3') # 查找不到返回-1
-1 >>>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM