[Python-ideas] Simpler syntax for basic iterations
Ben Finney
ben+python at benfinney.id.au
Mon Oct 12 00:28:22 CEST 2015
Luciano Ramalho <luciano at ramalho.org>
writes:
> 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
> fd(100)
> lt(120)
Thank you, yes it's much clearer because you're not doing exactly the
same division multiple times.
So, to follow your clarification, this::
for __ in range(3):
forward(100)
turn_left(120)
already works and is quite clear (though, again, I don't claim it will
convince you).
> 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..."
Yes, the fact you weren't using it confused me too :-)
Which is why we advocate a name, ‘__’, that stands out and is used only
for dummy assignment.
--
\ “How wonderful that we have met with a paradox. Now we have |
`\ some hope of making progress.” —Niels Bohr |
_o__) |
Ben Finney
More information about the Python-ideas
mailing list