Search code examples
pythonmaxmininteger-overflow

Will an integer overflow in Python?


In languages such as Java, the integer value will overflow once it is larger than Integer.MAX_VALUE or when it is less than Integer.MIN_VALUE. I have seen posts where using a Long datatype was suggested as replacement for int data type.

Will an integer ever overflow in Python? If yes, please list such cases.


Solution

  • Found an answer here. https://www.daniweb.com/programming/software-development/threads/71008/comparing-python-and-c-part-1-integer-variables

    Very early versions of Python had a limit that was later removed. The limits now are set by the amount of memory you have in your computer. It automatically manages the integer object, which is initially set to 32 bits for speed. If it exceeds 32 bits, then Python increases its size as needed up to the RAM limit.