Maximum value of integers in Python

In this article, we discuss the maximum value of integers in python. We will consider python 2 and python 3 versions.

Python 2

In python 2, integers are internally handled using int and long data types. If the number value is beyond int’s maximum value of int it automatically switches to a long data type.

We can get the maximum value of the integer in Python 2 using sys.maxint.

sys.maxint – It returns the largest positive integer supported by Python’s regular integer type. This is at least 2**31-1 (2147483647).

import sys
print sys.maxint # Maximum value of  Integer

Output

2147483647
import sys
print -sys.maxint # Minimum value of  Integer

Output

2147483648

Python 3

In python 3, there is no limit to the value of integers and sys.maxint constant removed. It means python 3 can handle any large integers that the underlying hardware can support (32 bit or 64 bit).

Python 3 has sys.maxsize it indicates the platform’s pointer size and it limits the size of data structures like strings and lists.

Conclusion

In conclusion, there is no limit to the value of integers in Python 3, it depends only on the underlying hardware limit. Python2 has sys.maxint to give the maximum value of integer it can support. You can read about the len function in python here.

Leave a Comment