inspection
set.issubset
Returns True if every element of s is also in other. Method form accepts any iterable; <= requires a set. Use < for strict (proper) subset.
s.issubset(other) | s <= other Parameters
| Parameter | Purpose |
|---|---|
| other | An iterable (method) or set (operator) to test against |
| returns | bool |
Examples
>>> {1, 2}.issubset({1, 2, 3})
True Every element of the left is in the right.
>>> {1, 2} <= {1, 2}
True
>>> {1, 2} < {1, 2}
False <= allows equality; < is strict/proper subset.
>>> {1, 2}.issubset([1, 2, 3, 4])
True Method form accepts any iterable.
>>> set().issubset({1, 2})
True The empty set is a subset of every set.
Gotcha
<= and < require a set on the right; use .issubset() for a list or generator. Every set is a subset of itself; the empty set is a subset of everything.
Related methods
← All Python set methods · List methods · list vs tuple vs set