Multiple assignment and the expression on the right side

Suresh Jeevanandam jm.suresh at gmail.com
Tue Feb 21 02:25:29 EST 2006


Alex Martelli wrote:
> Suresh Jeevanandam <jm.suresh at gmail.com> wrote:
> 
>> 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].
> 
> Since the original text is:
> 
> """
> Each time the statement executes, the right-hand side expression is
> evaluated once. Each target gets bound to the single object returned by
> the expression.
> """

Alex,
	I should have read carefully.

I think I got confused because of "Each time" in the sentence which 
gives a feeling that it gets executed several times. Maybe, It could 
have been just written, "When the statement gets executed, the right 
hand side is evaluated once, and the result is assigned to each of the 
target".

	Thanks a lot.

regards,
Suresh

> it might be interesting to understand how you managed to translate ONCE
> into ONCE PER ASSIGNMENT TARGET.  I can most earnestly assure you that
> when I wrote ONCE I meant ONCE. If ONCE meant TWICE (or more), how could
> there be a guaranteed SINGLE OBJECT to which each target gets bound?
> 
>>       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 good command of English, maybe?  With that ONCE and SINGLE in there,
> no matter how much I try to, I just cannot see ambiguity in the words I
> had written.  Nevertheless, in your honor, I guess I will redundantly
> change the ONCE into JUST ONCE in the second edition (I do strive for
> maximum conciseness in the Nutshell, but I guess I can spare one extra
> four-letter word, even though this is the only time I ever heard anybody
> express any doubt or misunderstanding about this paragraph).
> 
> 
> Alex



More information about the Python-list mailing list