Python Set issubset() Method

Determines whether all items in the set are present in the specified set

Usage

The issubset() method returns True if all items in the set are present in the specified set, otherwise FALSE.

In set theory, every set is a subset of itself.

For example, A.issubset(A) is True.

Syntax

set.issubset(set)

Python set issubset() method parameters
ParameterConditionDescription
setRequiredA set to search for common items in

Basic Example

Example: Check if all items in A are present in B

A = {'yellow', 'red'}
B = {'red', 'green', 'blue', 'yellow'}

print(A.issubset(B))	# True

Venn Diagram:

Subset

Equivalent Operator <=

You can achieve the same result by using the <= comparison operator.

Example:

A = {'yellow', 'red'}
B = {'red', 'green', 'blue', 'yellow'}

print(A <= B)	# True

Find Proper Subset

To test whether the set is a proper subset of other, use < comparison operator.

Set A is considered a proper subset of B, if A is a subset of B, but A is not equal to B.

Example: Check if A is a proper subset of B

A = {'yellow', 'red'}
B = {'red', 'green', 'blue', 'yellow'}

print(A < B)	# True
A = {'yellow', 'red'}
B = {'yellow', 'red'}

print(A < B)	# False