What is sys.maxint in Python 3?
--
Track title: CC D Schuberts Piano Sonata D 850 in D
--
Chapters
00:00 Question
00:25 Accepted answer (Score 233)
01:00 Answer 2 (Score 104)
01:37 Answer 3 (Score 43)
02:18 Answer 4 (Score 31)
02:52 Thank you
--
Full question
https://stackoverflow.com/questions/1379...
Accepted answer links:
[sys.maxsize]: https://docs.python.org/3/library/sys.ht...
https://docs.python.org/3/whatsnew/3.0.h...
Answer 2 links:
[math.inf]: https://docs.python.org/3/library/math.h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #python3x
#avk47
ACCEPTED ANSWER
Score 251
The
sys.maxintconstant was removed, since there is no longer a limit to the value of integers. However,sys.maxsizecan 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 assys.maxintin previous releases on the same platform (assuming the same build options).
ANSWER 2
Score 105
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.
ANSWER 3
Score 32
Python 3 ints do not have a maximum.
If your purpose is to determine the maximum size of an int in C when compiled the same way Python was, you can use the struct module to find out:
>>> import struct
>>> platform_c_maxint = 2 ** (struct.Struct('i').size * 8 - 1) - 1
If you are curious about the internal implementation details of Python 3 int objects, Look at sys.int_info for bits per digit and digit size details. No normal program should care about these.
ANSWER 4
Score 5
Python 3.0 doesn't have sys.maxint any more since Python 3's ints are of arbitrary length. Instead of sys.maxint it has sys.maxsize; the maximum size of a positive sized size_t aka Py_ssize_t.