[Python-ideas] Simpler syntax for basic iterations
luciano at ramalho.org
Mon Oct 12 00:13:27 CEST 2015
On Sun, Oct 11, 2015 at 7:03 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> Luciano Ramalho <luciano at ramalho.org>
>> for n: # repeat block n times
>> Where n is any expression that evaluates to an integer.
> Huh? If ‘n’ is an expression that evaluates to one integer, then why are
> you also dividing by that one integer ‘n’ every time through?
That's the classic formula for drawing an N-sided polygon in Logo. N
can be any positive integer. Maybe this is clearer:
for 3: # draw a triangle
> I don't claim it will convince you, but I find compelling the fact that
> for n in range(FOO):
> already works fine and is quite clear.
It is quite clear for us. When teaching the first steps of programming
to kids with the Turtle module, `for x in range(n):` leaves us in the
unfortunate position of having to say: "we won't use that x for
anything, and I can't explain what range this until much later..."
> \ “Science is a way of trying not to fool yourself. The first |
> `\ principle is that you must not fool yourself, and you are the |
> _o__) easiest person to fool.” —Richard P. Feynman, 1964 |
> Ben Finney
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
| Author of Fluent Python (O'Reilly, 2015)
| Professor em: http://python.pro.br
| Twitter: @ramalhoorg
More information about the Python-ideas