Skip to content
Advertisement

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 assignment statements have the form and on

How does Python’s comma operator work during assignment?

I was reading the assignment statements in the Python docs ( http://docs.python.org/reference/simple_stmts.html#assignment-statements). In that it is quoted that: If the target is a target list enclosed in parentheses or in square brackets: The object must be an iterable with the same number of items as there are targets in the target list, and its items are assigned, from left to

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 slightly more

Advertisement