Ternary operator associativity

Michael Torrie torriem at gmail.com
Thu Mar 6 12:47:25 EST 2014


On 03/06/2014 04:34 AM, candide wrote:
> According to the official documentation, the ternary operator has left-to-right associativity :
> 
> -------------------
> Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right -- see section Comparisons -- and exponentiation, which groups from right to left).
> -------------------
> 
> 
> Nevertheless, the ternary operator grouping seems to be from right to left, compare :

I was reading a blog about PHP the other day and it mentioned PHP was
the only language he knew of that had ternary operator precedence going
left to right.  All other languages use right to left.  So I assume that
Python also uses right to left and that the documentation is a bug.




More information about the Python-list mailing list