Table of Python Set Methods
Functions Name | Description |
---|---|
add() | Adds a given element to a set |
clear() | Removes all elements from the set |
copy() | Returns a shallow copy of the set |
difference() | Returns a set that is the difference between two sets |
difference_update() | Updates the existing caller set with the difference between two sets |
discard() | Removes the element from the set |
frozenset() | Return an immutable frozenset object |
intersection() | Returns a set that has the intersection of all sets |
intersection_update() | Updates the existing caller set with the intersection of sets |
isdisjoint() | Checks whether the sets are disjoint or not |
issubset() | Returns True if all elements of a set A are present in another set B |
issuperset() | Returns True if all elements of a set A occupies set B |
pop() | Returns and removes a random element from the set |
remove() | Removes the element from the set |
symmetric_difference() | Returns a set which is the symmetric difference between the two sets |
symmetric_difference_update() | Updates the existing caller set with the symmetric difference of sets |
union() | Returns a set that has the union of all sets |
update() | Adds elements to the set |
Note: For more information about Python Sets, refer to Python Set Tutorial.
Python Set Methods
A Set in Python is a collection of unique elements which are unordered and mutable. Python provides various functions to work with Set. In this article, we will see a list of all the functions provided by Python to deal with Sets.