Python: How does multiple assignments work on the same line?

I know that assignment is an operator in Python, i.e. he does not value meaning other than expression. How does the next line of code work in Python? Explain what happens inside the Python interpreter (lexing, parsing, abstract syntax tree formation).

# this works spam = eggs = 'ham' # this doesn't work. Throws SyntaxError spam = (eggs = 'ham') 
+7
python expression
source share
1 answer

Why does the first line above work and the second does not work?

This is not about operator priority. This is the assigned syntax. It cannot be "reconfigured" by adding brackets.

Now for a complete answer (as @Rob comments already noted) see here and here .

+10
source share

All Articles