Python 判断字符串是否存在子字符串

Document 对象参考手册 Python3 实例

给定一个字符串,然后判断指定的子字符串是否存在于改字符串中。

实例

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

执行以上代码输出结果为:

存在!

Document 对象参考手册 Python3 实例

0 个评论

要回复文章请先登录注册