作者:英雄醉酒惜红颜_527 | 来源:互联网 | 2022-12-02 12:08
我打算获得int的最大大小
In [1]: import sys
In [2]: sys.getsizeof(int)
Out[2]: 400
这是否意味着python中的maxint是2**40
但是,当我尝试
In [5]: types = [int, float, complex, list, tuple, dict, set, True, False, None]
In [7]: [sys.getsizeof(type) for type in types]
Out[7]: [400, 400, 400, 400, 400, 400, 400, 28, 24, 16]
所有数据类型都是400字节.
400字节对整数意味着什么?
1> Networker..:
在你的代码中,你得到的类的大小不是类的实例.
调用int以获取实例的大小,如下面的代码
>>> sys.getsizeof(int())
24