Set methods in Python

There are several in-built methods used for the manipulation of set. They are explained below:

a) isdisjoint() method The isdisjoint() method checks if any element of given set is present in another set. This method returns False if items are present, else it returns True.

Python

a = {1, 2, 3}
b = {4, 5, 6}
c = {3, 5}

print(a.isdisjoint(b))  # True → no overlap
print(a.isdisjoint(c))  # False → both contain 3

b) issuperset() method The issuperset() method checks if all the items of a particular set are present in the original set. It returns True if all the items are present, else it returns False.

Python

a = {1, 2, 3}
b = {4, 5, 6}
c = {3, 5}

print(a.isdisjoint(b))  # True → no overlap
print(a.isdisjoint(c))  # False → both contain 3