How to make a reverse for loop in python?

Mensanator mensanator at aol.com
Sat Sep 20 12:30:27 EDT 2008


On Sep 20, 11:16�am, Alex Snast <asn... at gmail.com> wrote:
> Hello
>
> I'm new to python and i can't figure out how to write a reverse for
> loop in python
>
> e.g. the python equivalent to the c++ loop
>
> for (i = 10; i >= 0; --i)

>>> for i in xrange(10,-1,-1): print i,

10 9 8 7 6 5 4 3 2 1 0

Note the starting number is 10, the ending
number is -1 because you want to include 0
and the step size is -1.



More information about the Python-list mailing list