Can someone please help explain why I am unable to print
>>> list(range(4**4**4)).
I am receiving an error OverflowError: range() result has too many items
Can someone please help explain why I am unable to print
>>> list(range(4**4**4)).
I am receiving an error OverflowError: range() result has too many items
According to official docs:
https://docs.python.org/2/library/sys.html#sys.maxsize https://docs.python.org/3/library/sys.html#sys.maxsize
sys.maxsize The largest positive integer supported by the platform’s Py_ssize_t type, and thus the maximum size lists, strings, dicts, and many other containers can have.
Try this code to check whether you would be able to create list of your size:
>>> import sys
>>> sys.maxsize > 4**4**4
and try this to verify how python resolves powers in your case:
>>> print(2**2**3)
256
>>> print(2**(2**3))
256
>>> print((2**2)**3)
64
You will get an OverflowError if the list has more elements than can be fit into a signed long:
For example your number is very big: