Is there a lower bound? Or does it literally starts from 1 byte and grows according to integer size?
int是一个对象。它肯定不能只有1字节长。在
下界可以用sys.getsizeof(0)得到
在我的机器上:>>> sys.getsizeof(0)
24
>>> sys.getsizeof(10000000000000000000000)
36
>>> sys.getsizeof(1<<31)
32
>>> sys.getsizeof(10000000000000000000000000000000000000000000)
44
在Python2中,int使用本机整数,直到无法使用为止,然后使用long。在python3中,所有东西都是long,因此值24与版本和机器相关(32/64位),但是是一个下限。在Can a lower bound or any bound for that matter of fact be applied to integer variables in python?
是的,只要你有足够的内存上限就行了。如上所示,整数越大,整数对象就越大。在
如果你知道你的整数的最大值,那么有一个上界。在If I have an array of integers is it likely that each index has different number of bytes depending on the integer it is holding? or Does python guarantee uniform size in arrays?
与C数组不同,该数组包含整数的引用。所以数组大小本身是很容易预测的。在
^{pr2}$
看看存储在里面的值是如何影响结果的,而只影响数组的大小?在
这是因为您必须考虑每个int对象的大小,正如上面所示,它是可变的,这是预测问题的核心。在