Python Set issubset() Method
Example
Return True if all items in set
x
are present in set y
:
x = {"a", "b", "c"}
y = {"f", "e", "d",
"c", "b", "a"}
z = x.issubset(y)
print(z)
Try it Yourself »
Definition and Usage
The issubset()
method returns True if all items
in the set exists in the specified set, otherwise it returns False.
As a shortcut, you can use the <=
operator instead, see example below.
Syntax
set.issubset(set1)
Shorter Syntax
set <= set1
Parameter Values
Parameter | Description |
---|---|
set1 | Required. The set to search for equal items in |
More Examples
Example
Use <=
as a shortcut instead of
issubset()
:
x = {"a", "b", "c"}
y = {"f", "e", "d",
"c", "b", "a"}
z = x <= y
print(z)
Try it Yourself »
Example
What if not all items are present in the specified set?
Return False if not all items in set
x
are present in set y
:
x = {"a", "b", "c"}
y = {"f", "e", "d",
"c", "b"}
z = x.issubset(y)
print(z)
Try it Yourself »