Is there some pre-defined constant like INT_MAX
?
Asked
Active
Viewed 7.1k times
1 Answers
134
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
. int
s use a C type, while long
s are arbitrary precision. You can use sys.maxint
to find the maximum int
. But int
s 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.

Matthew Flaschen
- 278,309
- 50
- 514
- 539
-
31Note that in Python 3 (and Python 2.6 and up) `sys.maxsize` can be used when you need an arbitrarily-large value. – mattdm Jan 23 '12 at 19:07
-
1
-
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) – Tadhg McDonald-Jensen Mar 11 '17 at 21:14
-
2