Multiple assignment and the expression on the right side

Terry Hancock hancock at anansispaceworks.com
Tue Feb 21 14:16:58 EST 2006


On Tue, 21 Feb 2006 10:53:21 +0530
Suresh Jeevanandam <jm.suresh at gmail.com> wrote:
> 	I read in "Python in a Nutshell" that when we have
> 	multiple assignments 
> made on a single line, it is equivalent to have those many
> simple  assignments and that the right side is evaluated
> once for each  assignment. [The wordings are mine. I am
> not sure if this is what he  intended].

>  >>> c = d = e = x()

AFAIK, this is equivalent to this:

e = x()
d = e
c = d

So, in fact, what you say is true, but these, of course will
not evaluate x multiple times.

-- 
Terry Hancock (hancock at AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com




More information about the Python-list mailing list