PEP 276 Simple Iterator for ints

James_Althoff at i2.com James_Althoff at i2.com
Wed Nov 28 16:49:55 EST 2001


Jim wrote:
>Lulu wrote:
>>  >>> if i in 100:  print 'even Natural' # I have no idea what this
MEANS!
>
>Small point, but it would just mean the same as:
>
>  >>> if i in xrange(100):
>
>as in, e.g.,
>
> >>> i = 2
> >>> if i in xrange(100):
> ...     print 'spam'
> ...
> spam
> >>>
>
>You just wouldn't have to read or write the xrange thing. :-)
>
>Jim

And this might be handy in common situations where you could write, for
example:

if index not in len(mylist):
    print 'index out of range'

instead of

if index not in xrange(len(mylist)):
    print 'index out of range'

Jim






More information about the Python-list mailing list