2. 集合的访问
in / not in 运算符
作用
- 用 in 可以判断一个值是否存在于集合中,如果存在返回 True, 否则返回 False
- not in 的返回值与 in 相反
示例
>>> s = {11, 22, 33}
>>> 22 in s
True
>>> 666 in s
False
>>> 'hello' not in s
True
集合是可迭代对象
集合是可迭代对象。
示例
>>> s = {300, 400, 500}
>>> for x in s:
... print(x)
...
400
300
500