Skip to content

Instantly share code, notes, and snippets.

@mahmoud
Created August 25, 2011 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahmoud/1169652 to your computer and use it in GitHub Desktop.
Save mahmoud/1169652 to your computer and use it in GitHub Desktop.
range() and xrange() limits
>>> import sys
>>> xrange(sys.maxint)
xrange(9223372036854775807)
>>> xrange(sys.maxint+1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C long
>>> range(sys.maxint+1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: range() result has too many items
>>> range(sys.maxint)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError
>>> range(sys.maxint-1, sys.maxint+1)
[9223372036854775806L, 9223372036854775807L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment