我只是在内存中测试了 python 数据结构的大小:
import sys
lst1=[]
lst1.append(1)
lst2=[1]
print(sys.getsizeof(lst1), sys.getsizeof(lst2))
我在以下配置上测试了代码:
52 40,因此 lst1有52个字节,lst2有40个字节。48 3248 36有人能解释一下为什么两个大小不同,虽然都是包含1的列表?
在 getsizeof 函数的 python 文档中,我发现了以下内容: ...adds an additional garbage collector overhead if the object is managed by the garbage collector.在我的小示例中会出现这种情况吗?