I checked maximum size of the integer Python holds using sys.maxsize
and it returned me 9223372036854775807
.
Then why I can still store a value greater than this range?
How many bytes are required to store an integer and do Python changes number of bytes depending on the size of an integer?
I am using Python 3.6
If you check the docs for sys.maxsize
, you'll see
sys.maxsize
An integer giving the maximum value a variable of typePy_ssize_t
can take. It’s usually2**31 - 1
on a 32-bit platform and2**63 - 1
on a 64-bit platform.
There's nothing in there about Python int
s! It's talking about Py_ssize_t
, an internal C API thing with no practical relevance to working with Python int
s.
Python int
s use an arbitrary-precision representation that will use more bytes of memory to represent bigger integers. They are not limited by the values of Py_ssize_t
s.
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