Python Collection Methods
Python Set Methods
The following methods are defined in the Python set class:
Number | Method and Description |
---|---|
1 | add() Adds an element to a set. |
2 | clear() Removes all elements from a set. |
3 | copy() Returns a shallow copy of a set. |
4 | difference() Returns the difference of two or more sets as a new set. |
5 | difference_update() Removes all elements from a set. |
6 | discard() Removes an element from a set if it exists. |
7 | intersection() Returns the intersection of two sets as a new set. |
8 | intersection_update() Updates a set so that it is the intersection of itself and another set. |
9 | isdisjoint() Returns True if the two sets do not intersect. |
10 | issubset() Returns True if the set is contained in the other set. |
11 | issuperset() Returns True if the set is contained in the other set. |
12 | pop() Removes and returns an arbitrary element from a set. |
13 | remove() Removes an element from a set; the element must be a member of the set. |
14 | symmetric_difference() Returns the symmetric difference of two sets as a new set. |
15 | symmetric_difference_update() Updates a set to be the symmetric difference of itself and another set. |
16 | union() Returns the union of the sets as a new set. |
17 | update() Updates a set to be the union of itself and another set. |