PEP 276 Simple Iterator for ints (fwd)

Peter Hansen peter at engcorp.com
Wed Nov 28 18:38:55 EST 2001


Rainer Deyke wrote:
> 
> "Peter Hansen" <peter at engcorp.com> wrote in message
[...]
> > But range() can be looked up.  You can type range(5)
> > at the interactive prompt (where a newbie would live)
> > and see [0, 1, 2, 3, 4] and infer immediately that
> > you are stepping through the items one at a time.
> > Typing 0 <= i < 5 at the prompt gives you either
> > 0 or 1, or NameError: name 'i' is not defined.
> > Not helpful for a newbie.
> 
> You are missing the point.  Typing 'i in range(5)' gives the same result at
> the interactive prompt.  So does 'i in [0, 1, 2, 3, 4]'.

I don't understand the point.  I wouldn't have expected
anyone to type "i in range(5)" at the prompt, but simply
"range(5)", resulting in a list, from which the hypothetical
newbie would likely infer that the for statement was iterating
over the items in that list.

Typing "i in range(5)" would produce an error message if
i did not already exist, as would 0 <= i < 5, but I 
wouldn't think anyone would try typing that to learn
what the for statement was doing...

(I'm speaking from personal experience in this case,
possibly experience which is not relevant to the example.
When I was learning Python, I ignored the tutorial at
first (just my learning style: dive in and see how 
long I can swim) and just looked at bits of code that
I found and experimented with the prompt.  At one
point I remember being surprised and pleased when
I discovered the nature of the "for" statement,
unique in my experience, as I typed range(5) at the
prompt and suddenly realized how "for" really
worked in Python.  I wouldn't have had that
experience if the syntax had been as suggested.)

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list