[Tutor] Inverse range
Alan Gauld
alan.gauld at freenet.co.uk
Wed Sep 6 19:39:44 CEST 2006
> I am playing with Python. Playing as in learning.
> Is it possible to reverse a range sequence? If, for instance, I
> call:
>
> for f in range( 1,5 ):
> print f
>
> Is it possible to reverse it? As in:
> 4
> 3
> 2
> 1
Yes, there is a normally unused third parameter to range
used to control the step size. It can bew negative so:
range(4,0,-1)
does what you want...
Alan G.
More information about the Tutor
mailing list