Python Tutorial Python Advanced Python References Python Libraries

Python Set - issuperset() Method



The Python issuperset() method is used to check whether all elements of specified set are present in the specified set or not. It returns true if all elements of specified set are present in the given set, else returns false. Please note that, this method can take iterable as an argument also.

Note: Set A is called superset of set B if all the elements of set B are present in set A. The below figure depicts two sets called A = {10, 20, 30, 40, 50, 60} and B = {10, 30, 60}. As all the elements of B are present in A, hence, A is called superset of B.

Superset

Syntax

set.issuperset(iterable)

Parameters

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

Return Value

Returns True if all elements of specified set are present in the given set, else returns False.

Example:

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

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

SetB = {10, 30, 60}
SetC = {5, 10, 15, 20, 25}

ListB = [10, 30, 60]
ListC = [5, 10, 15, 20, 25]

print(SetA.issuperset(SetB))
print(SetA.issuperset(SetC))
print()

print(SetA.issuperset(ListB))
print(SetA.issuperset(ListC))

The output of the above code will be:

True
False

True
False

❮ Python Set Methods