Augmented Assignment (was: Re: PEP scepticism)

Delaney, Timothy tdelaney at avaya.com
Sun Jul 1 20:59:55 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
> >>>

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.

Tim Delaney




More information about the Python-list mailing list