What are the max and min values of integer in Python?

Let’s see what the min and max values of an integer are in Python. We will assume we are working on a 64-bit version of Python.

Using the maxsize method

There is a sys module which will help us to answer the above questions. Maxsize method will tell us the max value of integer in Python.

import sys

print(sys.maxsize)

It turns out the max integer is exactly 9223372036854775807 which is 2^63-1.

See also  Automating AWS Services with Boto3 and Python

However, to display the minimum value, use one of the following:

import sys
minSize = -sys.maxsize - 1
print(minSize)

or

import sys
minSize = ~sys.maxsize
print(minSize)

Min value of an integer is -9223372036854775808.