Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Python - Set issubset() Method



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

Note: Set B is called subset of set A if all 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, B is called subset of A.

Subset

Syntax

set.issubset(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 the set are present in specified set, else returns False.

Example:

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

SetA = {10, 30, 60}

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

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

print(SetA.issubset(SetB))
print(SetA.issubset(SetC))
print()

print(SetA.issubset(ListB))
print(SetA.issubset(ListC))

The output of the above code will be:

True
False

True
False

❮ Python Set Methods

5