[Tutor] Python Memory Allocation -- deep learning
steve at pearwood.info
Mon Jul 30 13:10:28 EDT 2018
On Mon, Jul 30, 2018 at 09:21:01AM -0600, Mats Wichmann wrote:
> (id does not necessarily mean memory location, by the way)
id() *never* means memory location in Python. id() *always* returns an
opaque integer ID number which has no promised meaning except to be
unique while the object is alive.
The interpreter has to generate an ID somehow. In Jython and IronPython,
the interpreter keeps a counter, and IDs are allocated as consecutive
numbers 1, 2, 3, 4, ... etc. In CPython, the object's memory address is
used to generate the ID, but the ID does not mean "memory address". If
the ID happens to match the memory address, that's an accident, not a
feature of the language.
More information about the Tutor