Bigint in Python

Ishaan Shrivastava Oct 10, 2023
Bigint in Python

Python has a significant upper hand while working with integers because it has no integer overflow problem, which allows the user to create variables without thinking about their size. However, it depends upon the amount of free memory available in the system.

Python also supports an integer type bignum, which stores arbitrarily very large numbers. In Python 2.5+, this integer type is called long, which does the same function as bignum, and in Python 3 and above, there is only one int that represents all types of integers irrespective of their size.

Example to show the type of integer in Python 2.7:

x = 10
print(type(x))
y = 111111111111111111111111111111111111111111111111111111111111111111
print(type(y))

Output:

<class 'int'>
<class 'long'>

Example to show the type of integer in Python 3:

x = 10
print(type(x))
y = 1111111111111111111111111111111111111111111111111111111111111111111
print(type(y))

Output:

<class 'int'>
<class 'int'>

The output clearly shows that, in later versions of Python, the interpreter on its own stores the large integer numbers.

Related Article - Python Integer