Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何强制python中的数字采用32位而不是64位_Python_Integer - Fatal编程技术网

如何强制python中的数字采用32位而不是64位

如何强制python中的数字采用32位而不是64位,python,integer,Python,Integer,所以,我的理解是,在64位系统中,python中声明的数字需要64位。为了减少内存,是否可以将其设置为32位?如果您有需要存储的数字列表,可以使用array.array('l')或array.array('l')。您也可以使用ctypes.c_int(),ctypes.c_uint(),ctypes.c_long(),或ctypes.c_ulong()将数字存储为四个字节。什么类型的数字,使用什么库?例如,在numpy中,您可以使用dtype获得非常具体的信息,但例如vanillaint(lon

所以,我的理解是,在64位系统中,python中声明的数字需要64位。为了减少内存,是否可以将其设置为32位?

如果您有需要存储的数字列表,可以使用
array.array('l')
array.array('l')
。您也可以使用
ctypes.c_int()
ctypes.c_uint()
ctypes.c_long()
,或
ctypes.c_ulong()
将数字存储为四个字节。

什么类型的数字,使用什么库?例如,在
numpy
中,您可以使用
dtype
获得非常具体的信息,但例如vanilla
int
long
在2.x中)是无限制精度的。为什么要这样做?这里有一个关于查找变量大小的老问题:Python整数不是“32位”或“64位”。它们是Python整数。你到底想解决什么问题?Python使用,当需要保存大整数时,整数的位宽度会增加。