## Python Set Functions & Methods – Python Tutorial

###### 4 weeks ago Lalit Bhagtani 0

In Python, Objects have built-in methods inside it, which can be used to perform actions on the object itself. We can call methods of any object by putting period after object variable and then the method name.

*Syntax: objectVariable.methodName( parameters.. )*

* objectVariable : variable containing object. *

* methodName : name of the method, which we like to execute.*

* parameters : extra parameter ( 0 or more ) pass into the method.*

**Python Set Functions & Methods: **

Some examples of python set functions & methods are as follows :

**add :-**It insert a single immutable element in the set.**remove :-**It remove a single element from the set. If element is not present in the set, it will raise a KeyError.**discard :-**It discard ( remove ) a single element from the set. If element is not present in the set, it will not raise a KeyError.**pop :-**It remove and return an arbitrary element from the set. If we try to pop an empty set, it will raise a KeyError.**clear :-**It remove all the elements from the set.**copy :-**It return a shallow copy of another set.**union :-**It return a union of two or more sets.**union_update :-**It perform the union operation on two or more sets and then update the set ( on which union_update method is invoked ) with elements generated by union operation.**intersection :-**It return a intersection of two or more sets.**intersection_update :-**It perform the intersection operation on two or more sets and then update the set ( on which intersection_update method is invoked ) with elements generated by intersection operation.**difference :-**It return a difference of two sets.**difference_update :-**It perform the difference operation on two sets and then update the set ( on which difference_update method is invoked ) with elements generated by difference operation.**symmetric_difference :-**It return a symmetric difference of two sets.**symmetric_difference_update :-**It perform the symmetric difference operation on two sets and then update the set ( on which symmetric_difference_update method is invoked ) with elements generated by symmetric difference operation.**issuperset :-**It returns true, if a set on which this method is invoked is a superset of a set passed as an argument otherwise it returns false.**issubset :-**It returns true, if a set on which this method is invoked is a subset of a set passed as an argument otherwise it returns false.**isdisjoint :-**It returns true, if all elements of a set on which this method is invoked is different from a set passed as an argument otherwise it returns false.

**References :-**

That’s all for Python Set Functions & Methods. If you liked it, please share your thoughts in comments section and share it with others too.