Re: x += ... is not the same than x = x + ... if x is mutable

2013-03-21 Thread Steven D'Aprano
On Thu, 21 Mar 2013 08:35:26 -0400, Colin J. Williams wrote: > On 21/03/2013 12:27 AM, Nobody wrote: >> On Wed, 20 Mar 2013 07:17:08 -0700, bartolome.sintes wrote: >> >>> I thought that x += ... was the same than x = x + ..., but today I >>> have realized it is not true when operating with mutable

Re: x += ... is not the same than x = x + ... if x is mutable

2013-03-21 Thread Colin J. Williams
On 21/03/2013 12:27 AM, Nobody wrote: On Wed, 20 Mar 2013 07:17:08 -0700, bartolome.sintes wrote: I thought that x += ... was the same than x = x + ..., but today I have realized it is not true when operating with mutable objects. It may or may not be the same. x += y will invoke x.__iadd__(y

Re: x += ... is not the same than x = x + ... if x is mutable

2013-03-20 Thread Nobody
On Wed, 20 Mar 2013 07:17:08 -0700, bartolome.sintes wrote: > I thought that x += ... was the same than x = x + ..., but today I have > realized it is not true when operating with mutable objects. It may or may not be the same. x += y will invoke x.__iadd__(y) if x has an __iadd__ method, otherwi

Re: x += ... is not the same than x = x + ... if x is mutable

2013-03-20 Thread Jussi Piitulainen
bartolome.sin...@gmail.com writes: > 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

x += ... is not the same than x = x + ... if x is mutable

2013-03-20 Thread bartolome . sintes
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 beha