python 判断字符串是否包含(不区分大小写)
通过in
运算符来检查或通过str.find("")
来检查
如果想要不区分大(upper()
)小(lower()
)写,可以将字符串全部转换为大写字母或小写字母
示例:
a = "Hello World,你好世界"
# 通过in运算符来检查。
if "Hello" in a:
print("Yes")
# 通过str.find("")来检查。
if a.find("Hello") != -1:
print("Yes")
# 如果想要不区分大小写,可以将字符串全部转换为大写字母或小写字母。
print(a.upper())# 全部转换为大写
print(a.lower())# 全部转换为小写
if "hello".upper() in a.upper():
print("Yes")