operator precedence

Tim Peters tim.one at home.com
Thu Dec 7 15:01:13 EST 2000

[posted & mailed]

[b_wiedermann at my-deja.com]
> I am looking for a list of operator precedence that has been updated
> to include information for Python 2.0.

The only operator added to Python since its first release was "lambda", and
that was 5 or 6 years ago.  Nothing relevant changed for 2.0 (or 1.6, or
1.5.2, or ...).

> Also, I am looking for association information. Should we assume
> that associativity is always from left to right, except for
> comparison operators?

That's what the page you point to below says:  "Operators in the same box
group left to right (except for comparisons ...".  It does not say, although
it should, that, e.g., in


i+j is evaluated before m+n.  For that matter, i is evaluated before j, and
m before n, and i+j before either of m or n.  It also doesn't say (but
should) that in

   f(e1, e2)

e1 is evaluated before e2, and f is evaluated before either of them.  Etc.
"Left to right" was intentional in more ways than the reference manual
explicitly says.

> What about assignment operators; they do not appear in the language
> reference at
> http://www.python.org/doc/current/ref/summary.html#l2h-332

That's because Python doesn't have assignment operators; it has assignment
statements (much in the same sense that if doesn't have an if/then/else
operator, but does have if/then/else statements).

evaluation-is-west-to-east-and-north-to-south-ly y'rs  - tim

More information about the Python-list mailing list