暂无 |

List-检测-in

用in语句来检查列表中是否有某个项目,如果返回 True 则有,返回False则没有

words = ["spam", "egg", "spam", "sausage"]
print("spam" in words)
print("egg" in words)
print("tomato" in words)

结果:
>>>
True
True
False
>>>
in运算符还用于确定字符串是否是另一个字符串的子字符串。

1

发表评论

    评价:
    验证码: 点击我更换图片
    最新评论