[Tutor] Range limited?

fleet@teachout.org fleet@teachout.org
Tue, 31 Jul 2001 15:53:18 -0400 (EDT)


Recap:

The discussion of the limits of an integer would not have occured
(perhaps) if I had checked more than one source!  The
"docs/ref/integers.html" says:

"Plain integer decimal literals must be at most 2147483647 (i.e., the
largest positive integer, using 32-bit arithmetic). Plain octal and
hexadecimal literals may be as large as 4294967295, but values larger than
2147483647 are converted to a negative value by subtracting 4294967296.
There is no limit for long integer literals apart from what can be stored
in available memory."

Unfortunately, I had checked "Learning Python" only - and that reference
(the one I've most used to date!) doesn't mention this limitation (or I
can't find it.)

Two other sources - "Python Essential Reference" and "Core Python
Programming" - both provide the bounds of the python integer.  (These are
recent purchases - and were lying on the desk unopened at the time I asked
the original question.)

Also found (while researching the integer question) - both range and
xrange operate with "integers" as arguments.  My uncomplicated
(?simplistic?) mind had seen this as "integer == number == (integer,
float, long, complex)."  Range and Xrange both convert the numbers to
integers and are therefore limited to a range of 2147483647 (or
-2147483648).

>>> range(long(5))
[0, 1, 2, 3, 4]
>>> type(range(long(5))[2])
<type 'int'>

					- fleet -