Python 检查项目是否存在于集合中
检查项目是否存在于集合中
要确定指定项目是否存在于集合中,请使用 in 关键字:
实例
检查集合中是否存在 "apple":
thisset = {"apple", "banana", "cherry"}
if "apple" in thisset:
print("Yes, 'apple' is in this set")
亲自试一试 »
要确定指定项目是否存在于集合中,请使用 in 关键字:
检查集合中是否存在 "apple":
thisset = {"apple", "banana", "cherry"}
if "apple" in thisset:
print("Yes, 'apple' is in this set")
亲自试一试 »
