Augmented Assignement (was: Re: PEP scepticism)
Alex Martelli
aleaxit at yahoo.com
Fri Jun 29 09:00:40 EDT 2001
"Bernhard Herzog" <bh at intevation.de> wrote in message
news:6qn16r7i69.fsf at abnoba.intevation.de...
> Carsten Geckeler <uioziaremwpl at spammotel.com> writes:
>
> > As mentioned above, for tuples the "+=" is completely natural, but not
for
> > lists.
>
> Funny, I mostly see it exactly the other way round. += modifies the left
> hand side in place, so it's natural for a list, but not for a tuple.
>
> I think the main problem (in as much as there actually is a problem) is
> that whether augmented assignment rebinds the left hand side depends on
> the type of object, i.e. whether the object implements the appropriate
Right! I think the main advantage (in as much as there actually is an
advantage) is that whether augmented assignment rebids the left hand
side depends on the type of object. i.e. whether the object implements
the appropriate methods. This is called *polymorphism* and is a concept
of *HUGE* power.
> methods, which is very different from normal assignment which always
> rebinds.
Do you consider:
fee.fie = foo
and/or
fee[fie] = foo
examples of "normal assignment"? Neither "always rebinds" -- it all
depends on the type of object, i.e. whether the object (fee) implements
the appropriate methods (__setattr__, __setitem__). Augmented
assignment, like attribute assignment and item assignment, is
polymorphic. Plain assignment to an _unqualified_ LHS isn't, so
maybe *THAT* one is the "odd man out"?-)
Alex
More information about the Python-list
mailing list