Python max int: Maximum Integer Value in Python
In Python 3, the int data type is essentially the same as the long type in Python 2, so the idea of a maximum int goes effectively. Python2 has two integer types, int and long, but Python3 has the only int.
Python seamlessly shifts from plain integers to long integers once you surpass this value. So most of the time, you won’t want to know it.
Python max int
There is no concept of max int in Python 3. The int type is unbounded in Python3. To check the current interpreter’s word size in Python 3, use the sys.maxsize. If you are using the sys module’s property, then you need to import it in your head of the file.
Now, you can use the maxsize property.
import sys print(sys.maxsize)
It is exactly 2^63 – 1, so you’ve got a 64-bit int.
The maximum value representable by an unsigned word in Python will be sys.maxsize * 2 + 1, and the number of bits in a word will be math.log2(sys.maxsize * 2 + 2).
The sys.maxsize is not the maximum possible value of int, and it is possible to handle larger values as memory is available.
Let’s find the data type of maximum integer using the type() function.
import sys print(type(sys.maxsize)) print(type (sys.maxsize + 1))
<class 'int'> <class 'int'>
If you still want a number that bigger than all the others, then you can use the following code snippet.
The inf is judged to be larger than any value of int.
Similarly, if you want to find a smaller number than the others, you can use the following code.
Max integer for Python 2
The maximum value for plain int values in Python 2 can be calculated with sys.maxint.
# For Python2 import sys print(sys.maxint)
Python 3 has unlimited precision, and there is no explicitly defined limit.
That is it for Python max int tutorial.