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 >>>

猜你喜欢

转载自www.cnblogs.com/star12111/p/8876786.html