實例(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 >>>