[Tutor] Inverse range
Senthil_OR at Dell.com
Senthil_OR at Dell.com
Wed Sep 6 19:51:59 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)
And then there is also this reversed() call:
>>> for f in reversed(range(1,5)):
print f
4
3
2
1
>>>
Thanks,
Senthil
More information about the Tutor
mailing list