all Python 3astterm
ast.Gt
operators
The marker for the comparison > in an ast tree: it sits in Compare.ops and has no fields.
Syntax
ast.Gt()
The chain 'a > b > c' is one Compare with two operators in ops and two values in comparators, not two nested comparisons — matching how Python evaluates it. Compare marker nodes by type (isinstance), not with ==: ast nodes have no __eq__, so ast.Gt() == ast.Gt() is False.
Examples
import ast
c = ast.parse('a > b > c', mode='eval').body
print(type(c).__name__, [type(o).__name__ for o in c.ops]) # → Compare ['Gt', 'Gt']
print(c.left.id, [x.id for x in c.comparators]) # → a ['b', 'c']
print(ast.Gt() == ast.Gt()) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy