How do chained assignments work?

python, python-3.x

Solution

They will not necessarily work the same if `somefunction` returns a mutable value. Consider:

>>> def somefunction():
...     return []
... 
>>> x = y = somefunction()
>>> x.append(4)
>>> x
[4]
>>> y
[4]
>>> x = somefunction(); y = somefunction()
>>> x.append(3)
>>> x
[3]
>>> y
[]

Problem

A quote from something: ``` >>> x = y = somefunction() ``` is the same as ``` >>> y = somefunction() >>> x = y ``` Question: Is ``` x = y = somefunction() ``` the same as ``` x = somefunction() y = somefunction() ``` ? Based on my understanding, they should be same because `somefunction` can only return exactly one value.

Original source

Related problems