all Python 3astterm
ast.Or
operators
The or operator in the op field of a BoolOp; the operands are listed in values.
Syntax
ast.Or()
A chain a or b or c is one BoolOp(Or) with three values, not nested pairs as with BinOp. Mixing and and or nests by precedence: a or b and c is an Or whose second value is a BoolOp(And). Or never appears in BinOp; the bitwise | is BitOr.
Examples
import ast
n = ast.parse('a or b or c', mode='eval').body
print(type(n).__name__, type(n.op).__name__, len(n.values)) # → BoolOp Or 3
m = ast.parse('a or b and c', mode='eval').body
print(type(m.values[1].op).__name__) # → And
See also
Open in the full glossarydocs.python.orgReport an inaccuracy