【发布时间】:2021-09-19 00:16:45
【问题描述】:
看下面的代码,当你看到 a=[1,2] 是一个同构类型 1st 和 2nd 的地址> 元素相差 32 位 但是在第二种情况下 a=[1,'a',3] 时,1st 和 2nd 元素的地址之间没有关系,但是1st 和 3rd 元素之间存在关系,即地址相差 64 位。 所以我想知道 memory 是如何处理的,索引是如何发生的,以及它是如何与 non hashable (即可变的)相关联的
>>> a=[1,2]
>>> print(id(a[0]))
4318513456
>>> print(id(a[1]))
4318513488
>>> a=[1,'a',3]
>>> print(id(a[0]))
4318513456
>>> print(id(a[1]))
4319642992
>>> print(id(a[2]))
4318513520
>>>
【问题讨论】:
-
仅供参考 - 您忘记包含“下面的代码”
-
使用代码块来包含代码,而不是图像。
标签: python arrays list memory hashable