Python arrays and sting formatting options

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc 'BlackJack' Rintsch

    #31
    Re: Python arrays and sting formatting options

    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

    Comment

    Working...