Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Python, what is `sys.maxsize`?

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)]' 
like image 528
Christopher Turnbull Avatar asked Jan 07 '18 15:01

Christopher Turnbull


People also ask

What is the use of sys module in Python?

The sys module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. It allows operating on the interpreter as it provides access to the variables and functions that interact strongly with the interpreter.

How do you increase max size in Python?

Generally, the maximum value representable by an unsigned word will be sys. maxsize * 2 + 1 , and the number of bits in a word will be math. log2(sys. maxsize * 2 + 2) .

What is the maximum possible length of integer in Python?

These represent numbers in the range -2147483648 through 2147483647.

How large can a Python list be?

According to the source code, the maximum size of a list is PY_SSIZE_T_MAX/sizeof(PyObject*) . On a regular 32bit system, this is (4294967295 / 2) / 4 or 536870912. Therefore the maximum size of a python list on a 32 bit system is 536,870,912 elements.


1 Answers

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.

like image 51
BoarGules Avatar answered Sep 29 '22 22:09

BoarGules