A question on modification of a list via a function invocation

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Sep 6 02:02:11 EDT 2017


On Wed, 06 Sep 2017 03:42:31 +0000, Stefan Ram wrote:

>   Well, this /is/ from the PRL:
> 
>       »An object's identity never changes once it has been created;
>       you may think of it as the object's address in memory.«.
>                              ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
>     - The Python Language Reference, Release 3.6.0;
>     3.1 Objects, values and types
> 
>   It's not called "reference", it's called "identity". But it might
>   agree with your idea of a pointer of an implementation.
>   And you /can/ print it.
> 
>>>> print( id( 'abc' ))
> 4163144


I just tried that in my handy Python interpreter:


steve at runes:~$ jython
Jython 2.5.3 (, Jun 21 2017, 18:05:17) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_151
Type "help", "copyright", "credits" or "license" for more information.
>>> print id("abcd")
2
>>> print id("abcd")
3
>>> print id(None)
4


Do they look like pointers or references to you? They don't to me. I'm 
not aware of any machine where pointers can point to odd numbers 
(although there probably are some) and I'm certainly not aware of any 
where consecutive pointers differ by 1.


I think the manual is badly worded. It is true that we *can* think of IDs 
as the address of objects in memory, we *shouldn't* because that's 
misleading and tempts the reader to draw the wrong conclusion.

IDs in Python are arbitrary integers. They have no meaning except to be 
distinct for any two objects existing at the same time.



-- 
Steven D'Aprano
“You are deluded if you think software engineers who can't write 
operating systems or applications without security holes, can write 
virtualization layers without security holes.” —Theo de Raadt



More information about the Python-list mailing list