Python 字符串检查
字符串检查
要检查字符串中是否存在某个短语或字符,可以使用关键字 in
或 not in
。
示例
检查以下文本中是否存在短语 "ain"
txt = "The rain in Spain stays mainly in the plain"
x = "ain" in txt
print(x)
自己尝试 »
示例
检查以下文本中是否不存在短语 "ain"
txt = "The rain in Spain stays mainly in the plain"
x = "ain" not in txt
print(x)
自己尝试 »