In Python, what is `sys.maxsize`?

2019-05-21 05:11发布

问题:

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.