Multiple assignment and the expression on the right side

Suresh Jeevanandam jm.suresh at gmail.com
Tue Feb 21 00:23:21 EST 2006


Dear all,
	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].

	So, In the following code snippet I expected the values of c, d, e to 
be different. But they are not? I am missing something... What is it?
 >>> a = 12
 >>> def x(): global a; a+=1; return(a)
...
 >>> x()
13
 >>> a
13
 >>> c = d = e = x()
 >>> c
14
 >>> d
14
 >>> e
14
 >>>

Thanks.
regards,
Suresh



More information about the Python-list mailing list