Is there a way to get the largest integer one can use in Python?

PythonInteger

Python Problem Overview


Is there some pre-defined constant like INT_MAX?

Python Solutions


Solution 1 - Python

Python has arbitrary precision integers so there is no true fixed maximum. You're only limited by available memory.

In Python 2, there are two types, int and long. ints use a C type, while longs are arbitrary precision. You can use sys.maxint to find the maximum int. But ints are automatically promoted to long, so you usually don't need to worry about it:

sys.maxint + 1

works fine and returns a long.

sys.maxint does not even exist in Python 3, since int and long were unified into a single arbitrary precision int type.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnosView Question on Stackoverflow
Solution 1 - PythonMatthew FlaschenView Answer on Stackoverflow