# Python Set Methods

by

Python Set Methods

A set is a collection which is unordered and unindexed. Python has a set of built-in methods that you can use on sets.

 Methods Description add() The set.add() method adds the specified element to the set clear() The set.add() method in Python removes all the elements from the set. copy() This method returns a Shallow Copy for the Set difference() The set.difference() method in Python returns a set containing the difference between two or more sets difference_update() The difference_update() method in Python removes the common elements from the original set that are also included in another, given set. discard() The set.discard() method in Python removes the specified  element from the Set. intersection() The set.intersection() method in Python returns a set  that contains the intersection or the common elements between or among the given sets. intersection_update() This method removes the elements in this set that are not present in other given set(s). isdisjoint() The set.disjoint() method in Python checks whether the specified sets are disjoint(whether two sets have a intersection) or not. issubset() This method returns a boolean value true is another set that contains this set. issuperset() The set.issuperset() method in Python Returns whether this set contains another set or not pop() The set.pop() method removes an arbitrary element from the set. remove() The set.remove() method in python removes the specified item from the set. symmetric_difference() This method returns a set with the symmetric differences of two sets symmetric_difference_update() This method Updates the original Set With Symmetric Difference of the given two sets. union() The union() method return a set containing the union of the set(s). update() The set.update() method in Python updates the set with the union of this set and others

Example 1

Output

Example 2

Output

Example 3

Output

by