Simple sue use reversed() function to reverse the range() function output in python. Another way is to use a negative step to create a range in reverse,
Python range reverse list example
Simple example code reversing a range or a sequence of numbers results in a sequence containing the numbers from the range in reverse order.
res = reversed(range(5)) print(list(res))
Another example (Sequence of numbers with negative step)
If you want to use only
range to achieve the same result, you can use all its parameters.
range(start, stop, step)
ra = range(3, 0, -1) for num in ra: print(num)
Do comment if you have any doubts and suggestions on this Python range topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.