all Python 3astterm
ast.RShift
operators
The bitwise right shift operator >> in the op field of BinOp and AugAssign nodes.
Syntax
ast.RShift()
Shifting binds looser than addition: a >> 1 + 1 means a >> (1 + 1), and the tree has a BinOp(Add) to the right of RShift; ast.unparse adds parentheses only where they are needed. For negative numbers >> rounds down (-5 >> 1 == -3), unlike truncating division in some other languages.
Examples
import ast
n = ast.parse('a >> 1 + 1', mode='eval').body
print(type(n.op).__name__, type(n.right.op).__name__) # → RShift Add
print(-5 >> 1) # → -3
See also
Open in the full glossarydocs.python.orgReport an inaccuracy