Python 判断字符串是否存在子字符串
给定一个字符串,然后判断指定的子字符串是否存在于该字符串中。
实例
def check(string, sub_str): 
    if (string.find(sub_str) == -1): 
        print("不存在!") 
    else: 
        print("存在!") 
 
string = "www.runoob.com"
sub_str ="runoob"
check(string, sub_str)
执行以上代码输出结果为:
存在!
 
 
 Python3 实例
 Python3 实例 
       
chunhui
412***830@163.com
参考:
string = "www.runoob.com" sub_str ="runoob" if sub_str in string: print('存在') else: print('不存在')chunhui
412***830@163.com