[docs] documentation error w/ associativity

Zach Wegner zwegner at gmail.com
Tue Oct 25 01:25:28 CEST 2011

The operator precedence table given at the bottom of
http://docs.python.org/reference/expressions.html says that all
expressions have left associativity, except for comparisons, which
chain, and exponentiation, which has right associativity. However,
conditional expressions also have right associativity:

>>> 'a' if 1 else 'b' if 0 else 'c'

>>> import ast
>>> ast.dump(ast.parse("'a' if 1 else 'b' if 0 else 'c'"))
"Module(body=[Expr(value=IfExp(test=Num(n=1), body=Str(s='a'), orelse=IfExp(test
=Num(n=0), body=Str(s='b'), orelse=Str(s='c'))))])"


More information about the docs mailing list