Is behavior of += intentional for int?

Carl Banks pavlovevidence at gmail.com
Mon Aug 31 13:59:41 EDT 2009


On Aug 31, 10:21 am, zaur <szp... at gmail.com> wrote:
> On 29 авг, 16:45, zaur <szp... at gmail.com> wrote:
>
>
>
>
>
> > Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
> > [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
> > Type "copyright", "credits" or "license()" for more information.>>> a=1
> > >>> x=[a]
> > >>> id(a)==id(x[0])
> > True
> > >>> a+=1
> > >>> a
> > 2
> > >>> x[0]
>
> > 1
>
> > I thought that += should only change the value of the int object. But
> > += create new.
> > Is this intentional?
>
> As a result of this debate is not whether we should conclude that
> there should be two types of integers in python: 1) immutable numbers,
> which behave as constant value; 2) mutable numbers, which behave as
> variable value?

You are free to use third-party modules (such as numpy) which provide
mutable numbers.

I see no reason to include any mutable number type standard library,
as not many people will require the performance benefits and/or
indirection of mutable numbers, and those who do are free to use third-
party modules that provide them.


Carl Banks



More information about the Python-list mailing list