Python Glossary Русский

all Python 3operatorfunction

operator.gt

comparison

Return a > b — the functional form of the "greater than" operator.

Syntax

operator.gt(a, b)

If the left operand cannot compare, Python tries the reflected operation of the right one: for gt that is the second argument's __lt__. So a class only needs __lt__ and __eq__, and functools.total_ordering fills in the rest. functools.partial fixes the left argument: partial(operator.gt, 10) is x → 10 > x, i.e. "less than ten".

Examples

import operator
print(operator.gt(3, 2))   # → True
print(operator.gt(2, 2))   # → False
print(operator.gt('b', 'a'))   # → True
pairs = [(3, 2), (1, 4), (5, 5)]
print([operator.gt(a, b) for a, b in pairs])   # → [True, False, False]
print(operator.gt(1, 'a'))   # → TypeError

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy