Latest Code Tutorials

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.

import sys

Now, you can use the maxsize property.

import sys




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 + 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




Python 3 has unlimited precision, and there is no explicitly defined limit.

That is it for Python max int tutorial.

See also

Python float

Format float values in Python

Python data types

Python double data type

Python division

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.