Operator precedence problem

Random832 random832 at fastmail.com
Sun Jun 5 13:19:33 EDT 2016


On Sun, Jun 5, 2016, at 02:53, ICT Ezy wrote:
> >>> 2 ** 3 ** 2 
> Answer is 512
> Why not 64?
> Order is right-left or left-right?

You're mixing up order of evaluation with operator associativity. The **
operator is right-to-left associative, this means x ** y ** z == x ** (y
** z). Evaluation is left to right, where it matters [i.e. if one or
more of the elements here were an expression with side effects]: first x
is evaluated, then tmp=y**z, then x**tmp. These are two entirely
different concepts.



More information about the Python-list mailing list