Python 检查集合中是否存在某一项

检查集合中是否存在某一项

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

实例

检查集合中是否存在 "apple":

thisset = {"apple", "banana", "cherry"}

if "apple" in thisset:
  print("是的,'apple' 在这个集合中")

亲自试一试