Augmented Assignment (was: Re: PEP scepticism)

Courageous jkraska1 at san.rr.com
Sun Jul 1 00:08:33 CEST 2001


>> 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)

They would believe you better if you gave a better example:

>>> tpl1 = (1,2,3)
>>> tpl2 = tpl1
>>> tpl2
(1, 2, 3)
>>> tpl2+=(4,5)
>>> tpl2
(1, 2, 3, 4, 5)
>>> tpl1
(1, 2, 3)
>>> list1 = [1,2,3]
>>> list2 = list1
>>> list2
[1, 2, 3]
>>> list2 += [4,5]
>>> list2
[1, 2, 3, 4, 5]
>>> list1
[1, 2, 3, 4, 5]
>>> 



More information about the Python-list mailing list