Skip to content

Tag: variable-assignment

Python Multiple Assignment Statements In One Line

(Don’t worry, this isn’t another question about unpacking tuples.) In python, a statement like foo = bar = baz = 5 assigns the variables foo, bar, and baz to 5. It assigns these variables from left to right, as can be proved by nastier examples like But the python language reference states that as…

Multiple assignment semantics

In Python one can do: I checked the generated bytecode using dis and they are identical. So why allow this at all? Would I ever need one of these instead of the others? Answer One case when you need to include more structure on the left hand side of the assignment is when you’re asking Python unpack a s…