Python Glossary Русский

all Python 3operatorfunction

operator.le

comparison

Return a <= b — the functional form of the "less than or equal" operator.

Syntax

operator.le(a, b)

For sets le tests for a subset: le({1}, {1, 2}) is true. That makes le on sets a partial order only: le({1}, {2}) and le({2}, {1}) are both false. As with lt, functools.partial fixes the left argument: partial(operator.le, 18) means x → 18 <= x.

Examples

import operator
print(operator.le(2, 2))   # → True
print(operator.le(3, 2))   # → False
scores = [5, 10, 3]
print([s for s in scores if operator.le(s, 5)])   # → [5, 3]
print(operator.le({1}, {1, 2}))   # → True
print(operator.le({1, 2}, {2, 3}))   # → False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy