Is using range() in for loops really Pythonic?

7stud bbxx789_05ss at yahoo.com
Sat May 10 22:37:05 EDT 2008


On May 10, 8:19 pm, John Salerno <johnj... at NOSPAMgmail.com> wrote:
> I know it's popular and very handy, but I'm curious if there are purists
> out there who think that using something like:
>
> for x in range(10):
>     #do something 10 times
>
> is unPythonic. The reason I ask is because the structure of the for loop
> seems to be for iterating through a sequence. It seems somewhat
> artificial to use the for loop to do something a certain number of
> times, like above.
>

x = range(10)
print x

--output:--
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]



More information about the Python-list mailing list