Python/gloss python check string

来自菜鸟教程
跳转至:导航、​搜索

<languages />

Python签入字符串

签入字符串

要检查字符串中是否存在某个短语或字符,我们可以使用关键字 in or 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)