[docs] Tutorial 4.3 Range, print(range(x)) does return list

Anatoly Y 2tolik at gmail.com
Tue Jun 15 17:25:40 CEST 2010


Hi,

http://docs.python.org/dev/py3k/tutorial/controlflow.html#the-range-function

| A strange thing happens if you just print a range:
| >>> print(range(10))
| range(0, 10)
| In many ways the object returned by range() behaves as if it is a
list, but in fact it isn’t.
| It is an object which returns the successive items of the desired
sequence when you iterate over it,
| but it doesn’t really make the list, thus saving space.


^^ This is not true for 3.2.1 and 2.6.4

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit
(Intel)] on win32
>>> print(range(5))
[0, 1, 2, 3, 4]
>>> type(range(5))
<type 'list'>

BR,
AY


More information about the docs mailing list