# Python Max int | Maximum value of int in Python

In this tutorial, we will look at what’s Python Max int in different versions of Python.

Python 3 has unlimited precision that means there is no explicitly defined max limit. The amount of available address space is considered to be a practical maximum limit in Python 3.

Let’s take a look at different versions of Python and its max limit using examples.

## Max int in Python 2

If you are using Python 2, you can find the maximum value of the integer using `sys.maxint`.

There is a max int limit in Python 2, and if you cross the max limit, it would automatically switch from `int `to `long`.

The max int limit in Python 2 is 9223372036854775807, and anything above this number will be converted automatically into long.

Example: Python 2 Max int Limit

``````# Python 2 Max Int

import sys
print(sys.maxint)
print (type(sys.maxint))
``````

Output

``````<type 'int'>
9223372036854775807``````

Example: Python 2 Conversion from int to long

``````# Python 2 Max int to long conversion

import sys

number= 9223372036854775807
print (type(number))
print(number)

new_number= number+1
print (type(new_number))
print(new_number)``````

Output

``````<type 'int'>
9223372036854775807
<type 'long'>
9223372036854775808``````

## Max int in Python 3

Python 3 does not have sys.maxint, and it does not have a maximum integer limit. However, we can use sys.maxsize to get the maximum value of the `Py_ssize_t `type in Python 2 and 3.

Example: Python 3 Max int Limit

``````# Python 3 Max Int

import sys
print(sys.maxsize)
print(type(sys.maxsize))``````

Output

``````9223372036854775807
<class 'int'>``````

In Python 2, once the max int limit is reached, the interpreter will convert into long, However in Python 3, both int and long are merged into one single datatype int, so there is no conversion.

The below example will show the Python interpreter word size, but technically, it does not have any max limit, and the amount of address available in the System is considered as the maximum limit.

So in our below example, you can see that the data type remains as an integer even after we increment the max integer number. We have also demonstrated that address is the max limit by storing a very long number and printing the type and value.

``````# Python 3 Max int

import sys

number= 9223372036854775807
print (type(number))
print(number)

new_number= number+1
print (type(new_number))
print(new_number)

another_number=9999999999999999999999999999999
print (type(another_number))
print(another_number)
``````

Output

``````<class 'int'>
9223372036854775807
<class 'int'>
9223372036854775808
<class 'int'>
9999999999999999999999999999999``````

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

##### You May Also Like ## [Solved] RuntimeWarning: invalid value encountered in double_scalars

The RuntimeWarning: invalid value encountered in double_scalars mainly occurs when you perform a complex mathematical operation using NumPy that involves extremely small or very large numbers and also if we pass an… ## ModuleNotFoundError: No module named ‘PIL’

Table of Contents Hide What is ModuleNotFoundError: No module named ‘PIL’?How to fix ModuleNotFoundError: No module named ‘PIL’?Solution 1 – Installing and using the Pillow module in a proper waySolution… ## Python String strip()

Table of Contents Hide strip() Syntaxstrip() Parametersstrip() Return ValueExample: Working of the strip() methodExample 2 – How to use strip() method in real world? The Python String strip() method is… ## Python TypeError: ‘NoneType’ object is not subscriptable

If you subscript any object with None value, Python will raise TypeError: ‘NoneType’ object is not subscriptable exception. The term subscript means retrieving the values using indexing. In this tutorial,… ## Python String index()

Table of Contents Hide index() Syntaxindex() Parametersindex() Return ValueDifference between index() method and find() methodExample 1: Find the index of a string in PythonExample 2: If string is not found… ## JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Table of Contents Hide JSONDecodeError: Expecting value: line 1 column 1 (char 0)Example JSONDecodeError: Expecting value: line 1 column 1 (char 0)Solution Other Possible SolutionsEnsure HTTP 200 status code and valid…