Python Glossary Русский

all Python 3astterm

ast.GtE

operators

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

Syntax

ast.GtE()

The name abbreviates 'greater than or equal', and it is a separate class, not a flagged Gt: isinstance(op, ast.Gt) will not catch >=. A mixed chain '0 <= i >= n' is legal and yields ops [LtE, GtE]. Compare marker nodes by type (isinstance), not with ==: ast nodes have no __eq__, so ast.GtE() == ast.GtE() is False.

Examples

import ast
c = ast.parse('0 <= i >= n', mode='eval').body
print([type(o).__name__ for o in c.ops])  # → ['LtE', 'GtE']
print(isinstance(c.ops[1], ast.Gt))  # → False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy