成员运算符
运算符 in
和 not in
测试一个值是否存在于或不存在于可迭代对象(字符串、列表、元组、集合、字典)中。
python
>>> 1 in [1, 2, 3]
True
>>> "ed" in ["ed", "py", "hi"]
True
>>> "ed" in ("ed", "py", "hi")
True
>>> 'ed' in {'ed': 1, 'py': 2} # 检查键
True
>>> "pen" not in ["pencil", "ink"]
True
>>> "pen" not in ["pen", "ink"]
False