Python arrays and sting formatting options

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Oct 3 10:57:51 CEST 2008


On Thu, 02 Oct 2008 18:15:59 -0700, bearophileHUGS wrote:

> What's a range(n)? A function that returns a list of n items, from 0 to
> n. This is easy to understand, while xrange(n) is a bit less easy to
> understand (a generator or generators).

<nitpick>

`xrange()` doesn't return a generator or iterator but an object that 
implements the sequence protocol:

In [159]: a = xrange(0, 10, 2)

In [160]: len(a)
Out[160]: 5

In [161]: a[0]
Out[161]: 0

In [162]: a[2]
Out[162]: 4

</nitpick>

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list