Python 3 教程 Python 判断字符串是否存在子字符串

shelton · 2022-03-15 13:57:57 · 热度: 9

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

实例

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

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

存在!

查看更多 Python 实例

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册