Augmented Assignment (was: Re: PEP scepticism)

Rainer Deyke root at rainerdeyke.com
Sun Jul 1 22:00:51 EDT 2001


"Delaney, Timothy" <tdelaney at avaya.com> wrote in message
news:mailman.994035602.29848.python-list at python.org...
> > >>> b = (1,2,3)
> > >>> id(b)
> > 15261292
> > >>> b += (4,5)
> > >>> b
> > (1, 2, 3, 4, 5)
> > >>> id(b)
> > 18736580
> > >>>
>
> Actually, that's not quite true. It would be quite legal for id(b) to be
> identical in one case - since b is the only reference to the tuple, the
> original tuple could be collected, and a new tuple with the same id()
could
> be allocated. It's unlikely, but possible.

An interesting (and AFAIK legal) optimization would be to make tuples act as
mutable objects with respect to augmented assignment if their reference is
1.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list