[Python-3000] Using range()

"Martin v. Löwis" martin at v.loewis.de
Thu Apr 24 16:58:40 CEST 2008


> Which is the normal way to "consume" a range object, item by item?

The normal way is a for loop.

The advanced way of invoking some method on the object (i.e. emulating
the for loop) is to first create an iterator from the range object.
You can't consume the range itself: it will always contain the same
numbers - just like you can't consume a list.

>>>> r = range(10000000000000000000)
>>>> r[0]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>     OverflowError: Python int too large to convert to C ssize_t
> 
> This is a bug, right?

I'd call it an implementation limitation.

Regards,
Martin


More information about the Python-3000 mailing list