list = [1,2,3]
print(id(list))
list = [1,2,3]
print(id(list))
list = [1,2,3]
print(id(list))
list = [1,2,3]
print(id(list))
23963968
23963008
23963968
23963008
v应该是恰好重用了链表的地址
你每次写list = [1,2,3]这句话,看似列表内容完全一样,其实还是重新创建了一个新的对象,list这个变量指向了一个新的对象,当然地址就不一样了
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.
https://docs.python.org/3/library/functions.html?highlight=id#id
>>> s='s'
>>> print(id(s))
388847220976
>>> s='s'
>>> print(id(s))
388847220976