PEP 276 Simple Iterator for ints (fwd)

James_Althoff at James_Althoff at
Thu Nov 29 02:45:27 CET 2001

David Eppstein wrote:
>I would rather view a for-loop as
>  "for" expression:
>where (currently) the expression must have as its top level operation the
>"in" operation and the lhs must be a variable.  The variable is set in all

>possible ways that make the expression true.  From this point of view,
>x in 5" looks really ugly, and "for 0 <= x < 5" makes a lot more sense: we

>now simply allow one more kind of expression in a for loop, one where the
>top level is a three-way comparison and the middle side of the comparison
>must be a variable.

I would have guessed, though, that given the current direction of Python
vis-a-vis iterators that

    for 0 <= x < 5:

would have to mean something like "0 <= x < 5" is special syntax built into
the for-loop statement that generates an iterator that enumerates the
integers 0,1,2,3,4.  It happens to look just like an expression which
*outside* the context of a for-loop evaluates to 0 or 1 instead of
producing an iterator (as was pointed out previously by Peter Hansen).


More information about the Python-list mailing list