[docs] Tutorial 4.3 Range, print(range(x)) does return list
Georg Brandl
georg at python.org
Sun Jun 27 12:58:30 CEST 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am 15.06.2010 17:25, schrieb Anatoly Y:
> 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'>
This is true for 2.6, but you were looking at the 3.x documentation.
Have a look at the tutorial section for 2.x, and you will see that
it documents range() as returning a list.
cheers,
Georg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
iEYEARECAAYFAkwnLtYACgkQN9GcIYhpnLBZTQCgo2bUDKxQfpw/zIlY4M5qDNcS
icEAnAmkXOhxotcja6gngqgZkxHwspwP
=50zt
-----END PGP SIGNATURE-----
More information about the docs
mailing list