Python Max int | Maximum value of int in Python
Tags: python, programming, codenewbie, tutorial
Published: 2021-10-28 04:42:59

---
title: Python Max int | Maximum value of int in Python
published: true
date: 2021-10-25 08:30:00 UTC
tags: #python #programming #codenewbie #tutorial
canonical_url: https://itsmycode.com/python-max-int-maximum-value-of-int-in-python/
---

ItsMyCode |

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 Comment](https://www.w3basic.com/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
# Python 2 Max Int

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

```

**Output**

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

**Example: Python 2 Conversion from int to long **

```python
# 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**

```python
<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
# Python 3 Max Int

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

**Output**

```python
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
# 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**

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

The post [Python Max int | Maximum value of int in Python](https://itsmycode.com/python-max-int-maximum-value-of-int-in-python/) appeared first on [ItsMyCode](https://itsmycode.com).