set.issubset()

Test set containment — is every element of self already in other?

Set methodPython 2.6+Live demo
Common call
required <= granted
Returns
True or False
Replaces
`all(x in other for x in self)` in one call
Watch out
empty set is a subset of ANY set — including empty (vacuous truth)
set.issubset(otherotherA single iterable — set, list, tuple, generator, string, dict (keys). issubset() accepts any iterable; the `<=` operator requires a set.type: iterable · required)
bool

Demo

Live evaluation
Try:
Inputs
asetself (comma-separated)
bsetother (comma-separated)
Output
{'1', '2'}.issubset({'1', '2', '3', '4'})
TypeError: 'object' object is not iterable

issubset returns True when every element of self also appears in other. Empty set is a subset of EVERY set — including itself and even other empty sets — because there is no element that could fail the check. Neither input is modified.

Parameters

NameTypeRequiredDescription
otheriterableyesA single iterable — set, list, tuple, generator, string, dict (keys). issubset() accepts any iterable; the `<=` operator requires a set.

Return value

boolTrue if every element of self is contained in other. Empty set is a subset of every set (vacuously). The `<=` operator does the same thing, but requires sets on both sides.

Common patterns

Permission check
Every required permission must be present.
if required_perms &lt;= granted_perms:
    allow()
Required fields present
Fold keys into sets and compare.
if required_fields &lt;= set(payload.keys()):
    process(payload)
else:
    missing = required_fields - set(payload.keys())
Test against any iterable
issubset accepts iterables; the operator does not.
required.issubset(open("granted.txt"))   # streams the file

Examples

1. Proper subset
{1, 2} &lt;= {1, 2, 3}
Returns
True
2. Equal is subset
{1, 2, 3} &lt;= {1, 2, 3}
Returns
True
3. Missing element
{1, 2, 4} &lt;= {1, 2, 3}
Returns
False
4. Empty is universal
set() &lt;= {1, 2, 3}
Returns
True
5. Empty subset of empty
set() &lt;= set()
Returns
True
6. Iterable other
{1, 2}.issubset([1, 2, 3, 4])
Returns
True
7. Strict subset
{1, 2} &lt; {1, 2, 3}
Returns
True (strict, not equal)

Pitfalls

1. set() is a subset of EVERYTHING — including set()
The vacuously-true case surprises everyone once. There is no element in the empty set that could fail the &quot;every element is in other&quot; test, so the answer is True.
Unexpected True
set().issubset(set())
True
Guard for empty
if a and a &lt;= b:
    ...     # non-trivial subset
both non-empty AND subset
2. issubset != strict subset
`a <= b` and `a.issubset(b)` allow equality. For strict subset use `a < b` (self is subset AND not equal to other).
Equal returns True
{1, 2, 3}.issubset({1, 2, 3})
True # equal counts
Strict operator
{1, 2, 3} &lt; {1, 2, 3}
False
3. The `<=` operator requires sets on both sides
issubset() accepts any iterable. `<=` does NOT — it needs a set on both sides.
Type error
{1, 2} &lt;= [1, 2, 3]
TypeError: '<=' not supported between instances of 'set' and 'list'
Method form
{1, 2}.issubset([1, 2, 3])
True
4. String iterables explode into characters
Same footgun as every other set method — a string passed as other is iterated as characters, so multi-char items in self will not match.
Char comparison
{"ab"}.issubset("abcd")
False # "ab" is not one of the chars
Wrap it
{"ab"}.issubset({"ab", "cd"})
True

When to use

Use it
  • Permission / capability checks (&quot;every required X is present&quot;)
  • Validating required-fields presence
  • Testing whether one collection is contained within another
  • Composing with other set operations for readable filter logic
Reach for something else
  • Strict subset needed → `<` operator
  • Just testing overlap → set.isdisjoint (or `&amp;` and check emptiness)
  • Ordered containment → convert to sorted tuples and compare
  • Very large sets where a linear all() check is more memory-efficient than materializing both as sets

Notes

Complexity
O(|self|) — hash table lookups into other
Return
bool — True or False
CPython impl
Objects/setobject.c :: set_issubset
Memory
No allocation for sets; other may be materialized into a temporary set if it is a plain iterable
Thread-safe
Safe against reads; not safe under concurrent writes to either input

FAQ

Same result, but issubset accepts any iterable and `<=` requires both sides to be sets. `<` is the STRICT subset (not equal). Method form is more flexible; operator form reads better in comparisons.

History

2.3
set type added; `<=` operator available immediately.
2.6
issubset() method accepts any iterable (not just sets).