Multiple assignment and the expression on the right side

Alex Martelli aleaxit at yahoo.com
Tue Feb 21 00:57:49 EST 2006


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.
"""

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