Terminology: "reference" versus "pointer"
Steven D'Aprano
steve at pearwood.info
Sat Sep 12 13:24:25 EDT 2015
On Sun, 13 Sep 2015 02:54 am, Rustom Mody wrote:
> This is from the docs
> https://docs.python.org/3/library/functions.html#id
Yes, what of it? What point do you think you are making?
> id(object)
>
> Return the "identity" of an object. This is an integer which is
> guaranteed to be unique and constant for this object during its
> lifetime. Two objects with non-overlapping lifetimes may have the same
> id() value.
>
> CPython implementation detail: This is the address of the object in
> memory.
What part of "CPython implementation detail" was too difficult for you to
understand?
id() is not an addressof function. It returns, and I quote:
"an integer which is guaranteed to be unique and constant for this object
during its lifetime"
which is *not the case for memory addresses*. Here are the IDs of a few
objects in Python:
steve at orac:~$ jython -c "print id(None); import sys; print id(sys)"
1
2
steve at orac:~$ ipy -c "print id(None); import sys; print id(sys)"
0
43
Are you going to argue that these are memory addresses? If not, what
relevance do you think the id() function has here?
Note: when I write my own Python implementation, all IDs will be negative
odd numbers.
--
Steven
More information about the Python-list
mailing list