I've been trying to find out how to represent a maximum integer, and I've read to use "sys.maxint"
. However, in Python 3 when I call it I get:
AttributeError: module 'object' has no attribute 'maxint'
value, which corresponds to 18,446,744,073,709,551,615 for the unsigned data type and ranges from -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 in the signed version. if we're running it on a 32-bit machine or higher.
maxint does not exist as there is no limit or maximum value for an integer data type. But we can use the sys. maxsize to get the maximum value of the Py_ssize_t type in Python 2 and 3. It is also the maximum size lists, strings, dictionaries, and similar container types can have.
It's usually 2^31 - 1 on a 32-bit platform and 2^63 - 1 on a 64-bit platform.
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 3's int
does not have a maximum size, but if you just need something that's 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")
.
In Python 3.5 onwards, you can use math.inf
.
Note: as per ely's comment, this may impact the efficiency of your code, so it may not be the best solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With