82

Is there some pre-defined constant like INT_MAX?

1
  • It is 2^31 - 1 in Python 32 and 2^63 - 1 Python 64 bit runtime system. Commented Feb 11, 2020 at 12:15

1 Answer 1

137

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.

4
  • 31
    Note that in Python 3 (and Python 2.6 and up) sys.maxsize can be used when you need an arbitrarily-large value.
    – mattdm
    Commented Jan 23, 2012 at 19:07
  • 1
    is there one that is not a long? Commented Feb 28, 2014 at 2:04
  • 1
    sys.maxsize continues to be the theoretical limit on size of containers for python 2 and 3 (theoretical because memory is the real limiting factor) Commented Mar 11, 2017 at 21:14
  • 3
    @mattdm sys.maxsize+1 is larger than that.
    – jarno
    Commented Apr 1, 2019 at 10:42

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.