The issubset()
method in Python is used to check whether a set is a subset of another set. It returns True if all elements of the set are present in another set, otherwise, it returns False.
Parameter Values
This function does not accept any parameters.Return Values
The issubset()
method returns a bool
value: True
or False
.
How to Use issubset()
in Python
Example 1:
The issubset()
method returns True
if all elements of a set are present in another set (which could be equal to or larger than the original set). Otherwise, it returns False
.
set1 = {1, 2, 3, 4}
set2 = {2, 4}
print(set2.issubset(set1)) # Output: True
Example 2:
The issubset()
method can also be used to check if a set is a subset of another set.
set1 = {1, 2, 3, 4}
set2 = {2, 4}
print(set1.issubset(set2)) # Output: False
Example 3:
If there are elements in the set that are not present in the other set, issubset()
returns False
.
set1 = {1, 2, 3, 4}
set2 = {2, 4, 5}
print(set2.issubset(set1)) # Output: False