Python 检查列表项是否存在

检查列表项是否存在

要确定列表中是否存在指定的项,请使用 in 关键字:

实例

检查列表中是否存在 "apple":

thislist = ["apple", "banana", "cherry"]
if "apple" in thislist:
  print("是的,'apple' 存在于水果列表中")

亲自试一试