loops

John Machin sjmachin at lexicon.net
Sun Oct 19 12:17:51 CEST 2008



Steven D'Aprano wrote:

> On Sat, 18 Oct 2008 20:45:47 -0700, John Machin wrote:
>
> > On Oct 19, 2:30 pm, Steven D'Aprano <st... at REMOVE-THIS-
> > cybersource.com.au> wrote:
> > [snip]
> >> making your code easy to read and easy to maintain is far more
> >> important.
> >>
> >> for x in (2**i for i in xrange(10)):
> >>     print x
> >>
> >> will also print 1, 2, 4, 8, ... up to 1000.
> >
> > I would say up to 512; perhaps your understanding of "up to" differs
> > from mine.
>
> Well, mine is based on Python's half-open semantics: "up to" 1000 doesn't
> include 1000, and the highest power of 2 less than 1000 is 512.

We're talking about an English sentence, not a piece of Python code.
When you say "I'm taking the train to X", do you get off at the
station before X, as in "getting off at Redfern"?


>
> Perhaps you meant "up to and including 512".
>



More information about the Python-list mailing list