len(s)
返回集合 s 中的元素数量(即 s 的基数)。
x in s
检测 x 是否为 s 中的成员。
x not in s
检测 x 是否非 s 中的成员。
isdisjoint(other)
如果集合中没有与 other 共有的元素则返回 True。 当且仅当两个集合的交集为空集合时,两者为不相交集合。
issubset(other)set <= other
检测是否集合中的每个元素都在 other 之中。
set < other
检测集合是否为 other 的真子集,即 set <= other and set != other。
issuperset(other)set >= other
检测是否 other 中的每个元素都在集合之中。
set > other
检测集合是否为 other 的真超集,即 set >= other and set != other。
union(*others)set | other | ...
返回一个新集合,其中包含来自原集合以及 others 指定的所有集合中的元素。
intersection(*others)set & other & ...
返回一个新集合,其中包含原集合以及 others 指定的所有集合中共有的元素。
difference(*others)set - other - ...
返回一个新集合,其中包含原集合中在 others 指定的其他集合中不存在的元素。
symmetric_difference(other)set ^ other
返回一个新集合,其中的元素或属于原集合或属于 other 指定的其他集合,但不能同时属于两者。
copy()
返回原集合的浅拷贝。
| 留言与评论(共有 0 条评论) “” |