Augmented Assignment (was: Re: PEP scepticism)

Guido van Rossum guido at python.org
Fri Jun 29 08:42:30 EDT 2001


Paul Prescod <paulp at ActiveState.com> writes:

> That was a lot of effort to understand a typing shortcut. It's somewhat
> unpythonic to trade a long explanation for a bit less typing.

I think you're looking it the wrong way.

You shouldn't think "+= is confusing because sometimes it modifies an
object and sometimes it does".  Gee, there are lots of places where
something that's *spelled* the same has a different effect depending
on the object types involved.

The right way to think about this is "list objects are mutable and
tuples are not".  So if you want to give a library function a sequence
object of yours but you don't want it to be changed, pass it a tuple.
If you want it to be changed (or don't care) pass it a list.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list