首页 > 解决方案 > 确保字符串不包含链接的最佳方法是什么

问题描述

使用内置库确保字符串不包含链接 https:// 或 http:// 甚至只有地址(www.google.com)而不包含 http(s) 的最佳和干净的方法是什么

标签: python-3.x

解决方案


写一个 if 语句就足够了:

str1="https://www.google.com"
keyword="https://"
if keyword in str1:
    print("The chosen string contains a website link")

推荐阅读