Python 判斷字串是否存在子字串

Document 對象參考手冊 Python3 實例

給定一個字串,然後判斷指定的子字串是否存在於改字串中。

實例

def check(string, sub_str): if (string.find(sub_str) == -1): print("不存在!") else: print("存在!") string = "www.xuhuhu.com" sub_str ="zaixian" check(string, sub_str)

執行以上代碼輸出結果為:

存在!

Document 對象參考手冊 Python3 實例