Saturday, September 6, 2025
HomeLanguagesWhat is the maximum possible value of an integer in Python ?

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

Consider below Python program.
 

Python3




# A Python program to demonstrate that we can store
# large numbers in Python
  
x = 10000000000000000000000000000000000000000000
x = x + 1
print (x)


Output : 

10000000000000000000000000000000000000000001

In Python, value of an integer is not restricted by the number of bits and can expand to the limit of the available memory (Sources : this and this). Thus we never need any special arrangement for storing large numbers (Imagine doing above arithmetic in C/C++).
As a side note, in Python 3, there is only one type “int” for all type of integers. In Python 2.7. there are two separate types “int” (which is 32 bit) and “long int” that is same as “int” of Python 3.x, i.e., can store arbitrarily large numbers.
 

Python




# A Python program to show that there are two types in
# Python 2.7 : int and long int
# And in Python 3 there is only one type : int
  
x = 10
print(type(x))
  
x = 10000000000000000000000000000000000000000000
print(type(x))


Output in Python 2.7 : 
 

<type 'int'>
<type 'long'>

Python3




# A Python3 program to show that there are two types in
# Python 2.7 : int and long int
# And in Python 3 there is only one type : int
  
x = 10
print(type(x))
  
x = 10000000000000000000000000000000000000000000
print(type(x))


Output in Python 3 : 
 

<type 'int'>
<type 'int'>

We may want to try more interesting programs like below : 
 

Python3




# Printing 100 raise to power 100
print(100**100)


This article is contributed by Abhay Rathi. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6705 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS