python assignment

Grant Edwards grante at visi.com
Wed Jul 23 10:14:14 EDT 2003


In article <3F1E964E.BFD7513F at engcorp.com>, Peter Hansen wrote:
> Grant Edwards wrote:
>
>>> The examples you gave showed that integers share identity with
>>> other integers of the same value, while floats do not.
>> 
>> I believe that's only true for small integers, isn't it?
> 
> Google finds "LOADI - a fast load instruction for small positive integers 
> (those referenced by the small_ints array in intobject.c)" and checking
> that file is left as an exercise to the reader.  I'm going to blindly
> assume this is directly related to the issue in question... ;-)

I think so.  As others have pointed out, it's an implementation
detail, and the language definition doesn't require
equal-valued integer objects to share identity (nor is it
prohibited). Programs that rely on that behavior are broken.

Python 2.2.2 (#1, Jan 30 2003, 21:26:22) 
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> a=2
>>> b=2
>>> print id(a), id(b)
135297000 135297000
>>> a=123456789
>>> b=123456789
>>> print id(a), id(b)
135449020 135449032

-- 
Grant Edwards                   grante             Yow!  I invented skydiving
                                  at               in 1989!
                               visi.com            




More information about the Python-list mailing list