bdhar bdhar - 1 month ago 13
Python Question

Maximum and Minimum values for ints

I am looking for minimum and maximum values for integers in python. For eg., in Java, we have

Integer.MIN_VALUE
and
Integer.MAX_VALUE
. Is there something like this in python?

Answer

In Python 2, there's sys.maxint:

>>> sys.maxint
9223372036854775807

And you can calculate the minimum value with -sys.maxint - 1 as seen here. Of course Python just switches from plain to long integers once you exceed this value.

In Python 3 this value has no significance at all for integers. (However, a closely related value is still available as sys.maxsize, in case you're actually looking for the machine's word size.)

Comments