In Python, what is `sys.maxsize`?

依然范特西╮ 提交于 2019-12-21 09:06:48

问题


I assumed that this number ( 2^63 - 1 ) was the maximum value python could handle, or store as a variable. But these commands seem to be working fine:

>>> sys.maxsize 9223372036854775807

>>> a sys.maxsize + 1
>>> a 
9223372036854775808

So is there any significance at all? Can Python handle arbitrarily large numbers, if computation resoruces permitt?

Note, here's the print-out of my version is:

>>> sys.version
3.5.2 |Anaconda custom (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]'

回答1:


Python can handle arbitrarily large integers in computation. Any integer too big to fit in 64 bits (or whatever the underlying hardware limit is) is handled in software. For that reason, Python 3 doesn't have a sys.maxint constant.

The value sys.maxsize, on the other hand, reports the platform's pointer size, and that limits the size of Python's data structures such as strings and lists.



来源:https://stackoverflow.com/questions/48138632/in-python-what-is-sys-maxsize

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!