這是help(set)生成的官方文檔的翻譯,若有誤,請留言
Help on class set in module builtins:
class set(object)
| set() -> new empty set object #創建空集合
| set(iterable) -> new set object #通過可迭代對象創建集合
|
| Build an unordered collection of unique elements.
# 集合是一組無序不重複元素集
|
| Methods defined here:
|
| __and__(self, value, /)
| Return self&value.
|
| __contains__(...)
| x.__contains__(y) <==> y in x.
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __gt__(self, value, /)
| Return self>value.
|
| __iand__(self, value, /)
| Return self&=value.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __ior__(self, value, /)
| Return self|=value.
|
| __isub__(self, value, /)
| Return self-=value.
|
| __iter__(self, /)
| Implement iter(self).
|
| __ixor__(self, value, /)
| Return self^=value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __or__(self, value, /)
| Return self|value.
|
| __rand__(self, value, /)
| Return value&self.
|
| __reduce__(...)
| Return state information for pickling.
|
| __repr__(self, /)
| Return repr(self).
|
| __ror__(self, value, /)
| Return value|self.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(...)
| S.__sizeof__() -> size of S in memory, in bytes
|
| __sub__(self, value, /)
| Return self-value.
|
| __xor__(self, value, /)
| Return self^value.
|
| add(...)
| Add an element to a set.
| 往集合添加一個元素
| This has no effect if the element is already present.
| 如果元素已經存在則集合不會有變化
|
| clear(...)
| Remove all elements from this set.
| 刪除集合中所有元素
|
| copy(...)
| Return a shallow copy of a set.
| 返回集合的淺拷貝
|
| difference(...)
| Return the difference of two or more sets as a new set.
| (i.e. all elements that are in this set but not the others.)
| 返回b在a中的相對補集(即差集),即a-b={x|x∈a且x∉b}
| a.difference(b)表示返回a中有但b中沒有的元素集。返回的是新集合對象。
|
| difference_update(...)
| Remove all elements of another set from this set.
| 與上一個函數的區別是,返回的是經過處理的本對象(a)。
|
| discard(...)
| Remove an element from a set if it is a member.
| 從集合中刪除參數中指定的元素。
| If the element is not a member, do nothing.
| 若參數對應的元素不存在,則原集合不做操作
|
| intersection(...)
| Return the intersection of two sets as a new set.
| a.intersection(b).返回兩個集合的交集,返回的是新集合
| (i.e. all elements that are in both sets.)
|
| intersection_update(...)
| Update a set with the intersection of itself and another.
| 與上一個函數的區別是,運算得到的交集放在a中
|
| isdisjoint(...)
| Return True if two sets have a null intersection.
| 如果兩個集合交集爲空,則返回True,否則返回False
|
| issubset(...)
| Report whether another set contains this set.
| 若本集合是參數的子集,則返回True,否則返回False
|
| issuperset(...)
| Report whether this set contains another set.
| 若本集合包含參數集合(即參數是子集),則返回True,否則返回False
|
| pop(...)
| Remove and return an arbitrary set element.
| Raises KeyError if the set is empty.
| 刪除並返回集合中的第一個元素,若集合是空集則拋KeyError異常
| 注意:這個第一個元素與加入集合的先後順序無關,可能與元素的hash值對應的存儲位置有關。
|
| remove(...)
| Remove an element from a set; it must be a member.
| 從集合中刪除指定元素
| If the element is not a member, raise a KeyError.
| 若元素不存在則拋KeyError異常
|
| symmetric_difference(...)
| Return the symmetric difference of two sets as a new set
| a.symmetric_difference(b)。表示返回a∪b-a∩b。即將a、b的並集中a、b都有的元素刪除,返回新集合。
| (i.e. all elements that are in exactly one of the sets.)
|
| symmetric_difference_update(...)
| Update a set with the symmetric difference of itself and another.
| 與上一個函數的區別是,運算得到的集合放入a中,即a發生了變化
|
| union(...)
| Return the union of sets as a new set.
| a.union(b),返回兩個集合的並集,返回的是新集合
| (i.e. all elements that are in either set.)
|
| update(...)
| Update a set with the union of itself and others.
| 與上一個函數的區別是,生成的並集放在a中
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None