Address of an immutable object

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun May 30 19:19:13 EDT 2010


On Sun, 30 May 2010 22:08:49 +0200, candide wrote:

> Alf P. Steinbach a écrit :
>> * candide, on 30.05.2010 19:38:
>>> Suppose a Python program defines an integer object with value 42. The
>>> object has an "address" we can capture with the built-in function id()
>>> :
> 
>> First, id() doesn't generally provide an address.
> 
> I talked about a quote unquote "address" ;) but according to "The Python
> Language Reference" it's not very far from the truth  :
> 
> --------------------
> 3.1 Objects, values and types
> (...)
> An object’s identity never changes
> once it has been created; you may think of it as the object’s _address_
> in memory. The ‘is‘ operator compares the identity of two objects; the
> id() function returns an integer representing its identity (currently
> implemented as its _address_).
> --------------------
> 
> (emphasizing is mine)


Which is a weakness of the documentation, since in Jython object ids are 
1, 2, 3, 4, ... rather than addresses in memory. Of course, if you want 
to think of 1, 2, 3, 4, ... as addresses, who's going to stop you? :-)


-- 
Steven



More information about the Python-list mailing list