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