What is the maximum possible value of an integer in Python?


Unlike C/C++ Long in Python 3 have unlimited precision and there is no explicitly defined limit. The amount of available address space considered to be the practical limit.

In python 2, integers will automatically switch to longs when they grown beyond their limit −

Python 2

>>> import sys
>>> type(sys.maxint)
<type 'int'>
>>> type(sys.maxint + 1)
<type 'long'>

Python 3

Maxint was removed in python 3, but sys.maxsize can often be used instead.

>>> import sys
>>> type (sys.maxsize)
<class 'int'>
>>> type (sys.maxsize + 1)
<class 'int'>

From above output we can see, in python 3 int and long are actually merged and the value has no such importance.

#Python 2.7

>>> import sys
>>> print sys.maxint# Max Integer value
2147483647
>>> print -sys.maxint -1# Min. Ineteger value
-2147483648

But in python 3 we can assign a higher value than this as the range will be increased this time. The sys.maxint is replace by sys.maxsize.

#In Python 3.6

>>> import sys
>>> print(sys.maxsize)
2147483647

Largest & Smallest integers, longs and float values

#Python 2.7
import sys
print("Float value information: ",sys.float_info)
print("\n")
print("Long Integer value information: ",sys.long_info)
print("\n")
print("Maximum size of an integer: ",sys.maxsize)

output

('Float value information: ', sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, 
min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, 
mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1))
('Long Integer value information: ', sys.long_info(bits_per_digit=30, sizeof_digit=4))
('Maximum size of an integer: ', 9223372036854775807L)

#Python 3.6

import sys
print("Float value information: ",sys.float_info)
print("\nInteger value information: ",sys.int_info)
print("\nMaximum size of an integer: ",sys.maxsize)

output

Float value information: sys.float_info(max=1.7976931348623157e+308, max_exp=1024, 
max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, 
dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)
Integer value information: sys.int_info(bits_per_digit=15, sizeof_digit=2)
Maximum size of an integer: 2147483647


Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements