Python Set Methods
- Previous Page Python Tuple Methods
- Next Page Python File Methods
Python has a set of built-in methods that can be used on sets.
Method | Description |
---|---|
add() | Adds an element to the set. |
clear() | Removes all elements from the set. |
copy() | Returns a copy of the set. |
difference() | Returns a set that contains the differences between two or more sets. |
difference_update() | Removes items that are also included in another specified set. |
discard() | Removes the specified item. |
intersection() | Returns a set that is the intersection of two other sets. |
intersection_update() | Removes items that do not exist in the other specified set. |
isdisjoint() | Returns whether two sets have an intersection. |
issubset() | Returns whether another set contains this set. |
issuperset() | Returns whether this set contains another set. |
pop() | Removes an element from the set. |
remove() | Removes the specified element. |
symmetric_difference() | Returns a set that contains the symmetric difference of two sets. |
symmetric_difference_update() | Insert the symmetric difference of this set and another set. |
union() | Returns a set containing the union of sets. |
update() | update the set with the union of this set and other sets. |
In our Python Sets Tutorial Learn more about sets in Chinese.
- Previous Page Python Tuple Methods
- Next Page Python File Methods