Augmented Assignment (was: Re: PEP scepticism)

Emile van Sebille emile at fenx.com
Fri Jun 29 21:51:43 EDT 2001


It's nothing that examining the id doesn't resolve:

>>> a = [1,2,3]
>>> id(a)
18916180
>>> a += [4,5]
>>> a
[1, 2, 3, 4, 5]
>>> id(a)
18916180
>>> b = (1,2,3)
>>> id(b)
15261292
>>> b += (4,5)
>>> b
(1, 2, 3, 4, 5)
>>> id(b)
18736580
>>>

I think that once new users distinguish the object from the label things
start to fall into place appropriately.

--

Emile van Sebille
emile at fenx.com

---------
"Paul Prescod" <paulp at ActiveState.com> wrote in message
news:mailman.993841846.2132.python-list at python.org...
> Guido van Rossum wrote:
> >
> >...
> >
> > 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.
>
> My point is that it is hard for a new user to "believe me" (or at least
> understand me) when I say that tuples are not mutable but they see them
> changing right in front of their eyes:
>
> >>> a=(1,2,3)
> >>> a+=(8,3)
>
> The old behaviors strongly emphasized the non-mutability of things. The
> new operators undermine that understanding. Maybe the benefits outweigh
> this cost but I've seen this misunderstanding myself so I know it is a
> real cost.
> --
> Take a recipe. Leave a recipe.
> Python Cookbook!  http://www.ActiveState.com/pythoncookbook
>





More information about the Python-list mailing list