用in语句来检查列表中是否有某个项目,如果返回 True 则有,返回False则没有
words = ["spam", "egg", "spam", "sausage"] print("spam" in words) print("egg" in words) print("tomato" in words) 结果: >>> True True False >>>
1