# 例子: target='www.163.com' print(target.find('163')) if target.find('263')==-1: print('263不存在於字符串'+target+'中')
運行:
C:\Users\horn1\Desktop\python\7>python find.py 4 263不存在於字符串www.163.com中
當然,如果僅僅是字符串里是否存在子串的話,使用 in 和 not in 操作符更好。
# 例子: target='www.163.com' print(target.find('163')) if target.find('263')==-1: print('263不存在於字符串'+target+'中')
運行:
C:\Users\horn1\Desktop\python\7>python find.py 4 263不存在於字符串www.163.com中
當然,如果僅僅是字符串里是否存在子串的話,使用 in 和 not in 操作符更好。
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。