Python 判断字符串是否存在子字符串
Python 判断字符串是否存在子字符串的例子
给定一个字符串,然后判断指定的子字符串是否存在于改字符串中。
# Filename : example.py
# DateTime : 2020-07-20
# author by : www.lidihuo.com
def check(string, sub_str):
if (string.find(sub_str) == -1):
print("不存在!")
else:
print("存在!")
string = "www.lidihuo.com"
sub_str ="lidihuo"
check(string, sub_str)
执行以上代码输出结果为: