pythonpython-3.xdocumentationoperator-precedence

Why assignment operator and its 'variants' doesnt show up in the 'Precedence table' of python?


I was searching in the python documentation in order to get the 'Precedence table' of the operators in python, here it is (at least for python 3.12.7), Section 6.17:

https://docs.python.org/3.12/reference/expressions.html#operator-precedence

The final column says 'assignment expression', and shows the operator:

:=

Im learning python and i dont know this operator yet, but i expected to see in this column (or at least in the table) the operators like:

=, +=, -=, *=, /=, ...

Where are they? or how can i know whats the precedence of this operators? Why they are not present in the 'Precedence table'?

Thanks for your time


Solution

  • Those augmented assignments are not expressions. It doesn't make sense to mention the order of operation in this case since a = or *= can't appear in an expression. := is mentioned because it's an expression, so it can appear within other expressions.

    With an assignment statement, the entire right-hand side is evaluated before the left-hand side.