A Summary: Expression-Assignments. (Very Long)
guido at python.org
guido at python.org
Wed May 12 14:28:00 EDT 1999
Christian Tismer <tismer at appliedbiometrics.com> writes:
> The meaning of multiple assignments is:
> - Evaluate the right hand side and hold it
> - for each left hand side target expression
> - evaluate to assignable object
> - store value
>
> Example how this works
> (not recommended to use this side effect, tho:)
>
> a=b=c[a](5).x=1+2
>
> Evaluation of 1+2, temp=3
> Assign temp to a
> Assign temp to b
> Index c by current value which is 3
> Call the resulting function with argument 5
> Lookup the result's attribute "x"
> Assign temp to attribute "x".
>
> It is very consequent, and has nothing to do with a=(b=1) .
Historical note: Algol-60 (my first programming language) had multiple
assignment spelled as a:=b:=c, but no assignment expressions. I never
thought this was strange. When I first learned C, I thought it was
pretty neat how they had defined the binding for assignment
expressions so that a=b=c still meant what was familiar to me at the
time. So all I can do is smile when I hear that people are now coming
at Python's use of a=b=c from the opposite direction...
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list
mailing list