Python Glossary Русский

all Python 3Sets (set)function

set.issubset

checking

True if every element is contained in the other set (subset). Operator: <=.

Syntax

s.issubset(other)

The method accepts any iterable, while the <= operator demands sets on both sides: {1, 2} <= [1, 2, 3] raises TypeError. The empty set is a subset of everything, and every set is a subset of itself — for a proper subset, one that excludes equality, use <.

Examples

print({1, 2}.issubset({1, 2, 3}))   # → True
print({1, 4}.issubset({1, 2, 3}))   # → False
print({1, 2}.issubset([1, 2, 3]))   # → True
print(set().issubset({1, 2}))   # → True
print({1, 2} <= {1, 2}, {1, 2} < {1, 2})   # → True False
print({1, 2} <= [1, 2, 3])   # → TypeError

See also

Open in the full glossarydocs.python.orgReport an inaccuracy