Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python set isdisjoint() method is used to find out whether two sets have any common element or not. It returns true if there is no common element between two sets, else returns false. Please note that, this method can take iterable as an argument also.

Note: Two sets are called disjoint sets if there is no common element between them. The below figure depicts two sets called A = {10, 20, 30, 40, 50, 60} and B = {70, 80, 90}. As there is no common element between A and B, hence A and B are called disjoint sets.

Disjoint Sets

Syntax

set.isdisjoint(iterable)

Parameters

iterable Required. specify set or iterable which need to be compared with the given set.

Return Value

Returns True if there is no common element between two sets, else returns False.

Example:

In the below example, SetA is checked against SetB, SetC, ListB and ListC for disjoint sets using python isdisjoint() method.

SetA = {10, 20, 30, 40, 50, 60}

SetB = {70, 80, 90}
SetC = {5, 10, 15, 20, 25}

ListB = [70, 80, 90]
ListC = [5, 10, 15, 20, 25]

print(SetA.isdisjoint(SetB))
print(SetA.isdisjoint(SetC))
print()

print(SetA.isdisjoint(ListB))
print(SetA.isdisjoint(ListC))

The output of the above code will be:

True
False

True
False

❮ Python Set Methods




5