x += ... is not the same than x = x + ... if x is mutable
bartolome.sintes at gmail.com
bartolome.sintes at gmail.com
Wed Mar 20 10:17:08 EDT 2013
Hi,
I thought that x += ... was the same than x = x + ..., but today I have realized it is not true when operating with mutable objects.
In Python 3.3 or 2.7 IDLE (Windows) compare:
>>> a = [3]
>>> b = a
>>> a = a + [1]
>>> b
[3]
and
>>> a = [3]
>>> b = a
>>> a += [1]
>>> b
[3, 1]
Is this behaviour explained in the Python documentation?
Thanking you in advance,
Bartolomé Sintes
More information about the Python-list
mailing list