What is sys.maxint in Python 3?

What is sys.maxint in Python 3?

The sys.maxint constant was removed, since there is no longer a limit
to the value of integers. However, sys.maxsize can be used as an
integer larger than any practical list or string index. It conforms to
the implementation’s “natural” integer size and is typically the same
as sys.maxint in previous releases on the same platform (assuming the
same build options).

http://docs.python.org/3.1/whatsnew/3.0.html#integers

As pointed out by others, Python 3s int does not have a maximum size, but if you just need something thats guaranteed to be higher than any other int value, then you can use the float value for Infinity, which you can get with float(inf).

Note: as per elys comment, this may impact the efficiency of your code, so it may not be the best solution.

What is sys.maxint in Python 3?

If you are looking for a number that is bigger than all others:

Method 1:

float(inf)

Method 2:

import sys
max = sys.maxsize

If you are looking for a number that is smaller than all others:

Method 1:

float(-inf)

Method 2:

import sys
min = -sys.maxsize - 1

Method 1 works in both Python2 and Python3. Method 2 works in Python3. I have not tried Method 2 in Python2.

Related Posts

Leave a Reply

Your email address will not be published.