Consider below Python program.
# A Python program to demonstrate that we can store # large numbers in Python x = 10000000000000000000000000000000000000000000; x = x + 1 print (x)
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.
# 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'>
Output in Python 3 :
<type 'int'> <type 'int'>
We may want to try more interesting programs like below :
# 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
- Transpose a matrix in Single line in Python
- Tips and Tricks for Competitive Programmers | Set 2 (Language to be used for Competitive Programming)
- Global and Local Variables in Python
- Python | Set 2 (Variables, Expressions, Conditions and Functions)
- Secure coding – What is it all about?
- Find the number of operations required to make all array elements Equal
- Python | Plotting Data on Google Map using pygmaps package
- Python | Find Live running status and PNR of any train using Railway API
- Python | Data analysis using Pandas
- Creating linear kernel SVM in Python