Python 检查列表项是否存在
检查列表项是否存在
要确定列表中是否存在指定项目,请使用 in 关键字:
实例
检查列表中是否存在"apple":
thislist = ["apple", "banana", "cherry"]
if "apple" in thislist:
print("Yes, 'apple' is in the fruits list")
亲自试一试 »
要确定列表中是否存在指定项目,请使用 in 关键字:
检查列表中是否存在"apple":
thislist = ["apple", "banana", "cherry"]
if "apple" in thislist:
print("Yes, 'apple' is in the fruits list")
亲自试一试 »
