Python - Set Methods

Python - Set Methods


The Python has a number of methods and functions that are available for use with sets. These methods and functions are listed below in alphabetical order. For more details about any one of these, please visit its page.

Set Methods & Functions
MethodsDescription
Adds a specified element to the set
The Python has a number of methods and functions that are available for use with sets. These methods and functions are listed below in alphabetical order. For more details about any one of these, please visit its page. Deletes all the elements from the set
Returns a copy of the set
Returns a set containing all elements of the given set which are not present in the specified sets or iterables
Set Methods & Functions Deletes all elements from the given set which are present in the specified sets or iterables
Remove the specified element from the given set
Methods Returns a set which contains common elements of two or more sets
Description Deletes all elements from the given set which are not present in all specified set(s)
Returns True when two sets have any common element, else returns False
add() Returns True when all elements of the given set are present in specified set, else returns False
Returns True when all elements of the specified set are present in the given set, else returns False
Adds a specified element to the set Deletes a random element from the given set
Removes the specified element from the given set
clear() Returns a set with the symmetric differences of two sets
inserts the symmetric differences from the given set with another
Deletes all the elements from the set Return a set containing the union of sets
Update the set with the union of this set and others
FunctionsDescription
copy() Returns total number of elements in the set
set function/constructor is used to create set from iterable like list, tuple, set, string, dictionary and range() etc.



Recommended Pages

  • Returns a copy of the set
  • difference()