马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
set 和 frozenset 支持以下操作:
- key in s
检查 key 是 s 的成员,返回bool类型 True or False>>> 1 in {1,2,3}
True
>>> 2 in frozenset({1,2,3})
True
>>> 4 in {1,2,3}
False
>>> 4 in frozenset({1,2,3})
False
- key not in s
与key in s相反,检查 key 不是 s 的成员,返回bool类型 True or False>>> 1 not in {1,2,3}
False
>>> 2 not in frozenset({1,2,3})
False
>>> 4 not in {1,2,3}
True
>>> 4 not in frozenset({1,2,3})
True
- s1 == s2
判断两个集合是否等价,返回bool类型 True or False>>> {1,2,3} == {1,2,3}
True
>>> {1,2,3} == {3,1,2}
True
>>> frozenset({1,2,3}) == {1,2,3}
True
>>> frozenset({1,2,3}) == {2,1,3}
True
- s1 != s2
与s1 == s2相反,判断两个集合是否不等价,返回bool类型 True or False>>> {1,2,3} != {3,1,2}
False
>>> {1,2,3} != frozenset({3,1,2})
False
>>> {1,2,3} != {2,3,4}
True
- s1 <= s2
判断 s1 是 s2的子集,返回bool类型 True or False>>> {1,2,3} <= {1,2,3}
True
>>> {1,2,3} <= {1,2,3,4}
True
>>> {1,2,3} <= {2,3,4}
False
- s1 < s2
判断s1 是s2的真子集,返回bool类型 True or False>>> {1,2,3} < {1,2,3,4}
True
>>> {1,2,3} < {1,2,3}
False
>>> {1,2,3} < {2,3,4}
False
>>> {1,2,3} < frozenset({1,2,3,4})
True
>>> frozenset({1,2,3}) < {1,2,3}
False
>>> frozenset({1,2,3}) < {1,2,3,4}
True
- s1 >= s2
判断s1 是 s2 的超集,返回bool类型 True or False>>> {1,2,3} >= {1,2,3}
True
>>> {1,2,3} >= {1,2}
True
>>> {1,2,3} >= {1,2,3,4}
False
- s1 > s2
判断s1 是 s2 的真超集,返回bool类型 True or False>>> {1,2,3} > {1,2}
True
>>> {1,2,3} > {2,3,4}
False
>>> {1,2,3} > {1,2,3}
False
- s1 | s2
返回s1 与 s2的并集,如果s1是set(),则返回set();如果s1是frozenset(),则返回frozenset()>>> {1,2} | {2,3}
{1, 2, 3}
>>> frozenset({2,3}) | frozenset({1,3})
frozenset({1, 2, 3})
>>> frozenset({2,3})|{1,2}
frozenset({1, 2, 3})
>>> {1,2} | frozenset({2,3})
{1, 2, 3}
- s1 & s2
返回s1 与 s2的交集,如果s1是set(),则返回set();如果s1是frozenset(),则返回frozenset()>>> {1,2} & {2,3}
{2}
>>> {1,2} & frozenset({2,3})
{2}
>>> frozenset({1,3}) & {2,3}
frozenset({3})
>>> frozenset({1,3}) & frozenset({2,3})
frozenset({3})
- s1 - s2
返回s1 与 s2 的差集,如果s1是set(),则返回set();如果s1是frozenset(),则返回frozenset()>>> {1,2,3} - {1}
{2, 3}
>>> {1,2,3} - frozenset({1})
{2, 3}
>>> {1,2,3} - frozenset({1,2,3,4})
set()
>>> frozenset({1,2,3}) - {2}
frozenset({1, 3})
>>> {1,2,3} - {2,3,4}
{1}
- s1 ^ s2
返回s1 与 s2 的对称差分(该集合中的元素在s1与s2的其中之一),如果s1是set(),则返回set();如果s1是frozenset(),则返回frozenset()>>> {1,2,3} ^ {2,3,4}
{1, 4}
>>> {1,2,3} ^ frozenset({2,3,4})
{1, 4}
>>> frozenset({1,2,3}) ^ {2,3,4}
frozenset({1, 4})
>>> frozenset({1,2,3}) ^ frozenset({2,3,4})
frozenset({1, 4})
|