Python Glossary Русский

all Python 3astterm

ast.LtE

operators

The marker for the comparison <= in an ast tree: it sits in Compare.ops and has no fields.

Syntax

ast.LtE()

A separate class, not Lt with an 'or equal' flag: to catch both signs check isinstance(op, (ast.Lt, ast.LtE)). '<=' between sets (subset) gives the same LtE — the tree knows nothing about operand types. Compare marker nodes by type (isinstance), not with ==: ast nodes have no __eq__, so ast.LtE() == ast.LtE() is False.

Examples

import ast
c = ast.parse('a <= b', mode='eval').body
op = c.ops[0]
print(type(op).__name__, isinstance(op, ast.Lt), isinstance(op, (ast.Lt, ast.LtE)))  # → LtE False True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy