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)
Parameter | Condition | Description |
set | Required | A set to search for common items in |
Basic Example
# Check if all items in A are present in B
A = {'yellow', 'red'}
B = {'red', 'green', 'blue', 'yellow'}
print(A.issubset(B))
# Prints True
Equivalent Operator <=
You can achieve the same result by using the <=
comparison operator.
A = {'yellow', 'red'}
B = {'red', 'green', 'blue', 'yellow'}
print(A <= B)
# Prints 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.
# Check if A is a proper subset of B
A = {'yellow', 'red'}
B = {'red', 'green', 'blue', 'yellow'}
print(A < B)
# Prints True
# Check if A is a proper subset of B
A = {'yellow', 'red'}
B = {'yellow', 'red'}
print(A < B)
# Prints False