Identity function id() [was Re: Objects in Python]

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Aug 24 06:06:33 EDT 2012


On Thu, 23 Aug 2012 20:36:27 -0400, Roy Smith wrote:

> The id has changed!  Now, we all know that the id of an object is its
> memory address (that's not guaranteed, but in the standard C
> implementation of Python, that's what it is).

It's not only "not guaranteed", it is *explicitly* noted as an 
implementation detail. The id of the object is an arbitrary number 
guaranteed to be unique during the lifetime of that object. It just 
happens that CPython currently uses the memory address as the id. Jython 
does not:

steve at runes:~$ jython
Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19)
[OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 42
>>> id(x)
1


Nor does IronPython:

steve at runes:~$ ipy
IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 42
>>> id(x)
43



-- 
Steven



More information about the Python-list mailing list