Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it?

Roel Schroeven roel at roelschroeven.net
Wed Jun 16 14:49:16 EDT 2021


Dieter Maurer schreef op 16/06/2021 om 18:32:
> Chris Angelico wrote at 2021-6-16 02:20 +1000:
>> On Wed, Jun 16, 2021 at 2:18 AM Dieter Maurer <dieter at handshake.de> wrote:
>>> As far as I know, there are no guarantees are the language level.
>>> There are some (partially documented) implementation details
>>> for CPython (which is just one possible implementation).
>>
>> Yes there are - plenty of them :) The example I gave is a language
>> guarantee.
> 
> Would you point to the documentation location where this is guaranteed?

I lost track of which exact guarantee we're discussing here. In any 
case, the documentation for the id() function ([1]) says:

"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."

Does that answer your doubts?


[1] https://docs.python.org/3.8/library/functions.html?highlight=id#id

-- 
"Honest criticism is hard to take, particularly from a relative, a
friend, an acquaintance, or a stranger."
         -- Franklin P. Jones

Roel Schroeven



More information about the Python-list mailing list