On Thu, May 24, 2018 at 10:39:17PM -0700, Danny Yoo wrote:

> Each value in Python has an associated numeric address associated to it.

No they don't :-)

Each object in Python has an arbitrary numeric ID associated with it. 
The Python language has no supported way to get the address of an 
object. The id() function returns an opaque and officially meaningless 
ID number, that is all.

It so happens that CPython uses the (memory) address of the object as 
that ID number, but not all Python interpreters do the same. Jython and 
IronPython, for example, assign IDs in consecutive order, so you will 
get IDs like 20, 21, 22, 23, 24, etc.

(By memory, IronPython allocates the ID when the object is first 
created, while Jython allocates an ID only when you ask for one.)

The reason IronPython and Jython do that is because they run inside an 
environment where objects can be moved around memory by the memory 
manager and garbage collector. So if an object X has address 1234 at one 
moment, a little later it could be moved to address 9516. Using the 
address would not be stable.



-- 
Steve
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to