range() and xrange() take a third parameter that specifies a step. So you can do the following.

range(10, 0, -1)

Which gives

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1] 

But for iteration, you should really be using xrange instead. So,

xrange(10, 0, -1)

Note for Python 3 users: There are no separate range and xrange functions in Python 3, there is just range, which follows the design of Python 2's xrange.

Answer from Chinmay Kanchi on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ backward-iteration-in-python
Backward iteration in Python - GeeksforGeeks
July 11, 2025 - a = [10, 20, 30, 40, 50] #Loop through the list #using reversed() to reverse the order of list for b in reversed(a): print(b) ... Let's explore more methods that helps to iterate backward on any iterable. Here are some common approaches: ... range function is provided with three arguments(N, -1, -1). Use this method when we need to modify elements or access their indices. ... s = "Python" # - len(s) - 1: Start at the last index # - -1: Ensures the loop stops after the first character # - -1: The step value to iterate backwards for i in range(len(s) - 1, -1, -1): print(s[i])
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how can i loop through an array forward and then backwards and then forwards and... etc with the modulus operator?
r/learnpython on Reddit: How can I loop through an array forward and then backwards and then forwards and... etc with the modulus operator?
September 9, 2021 -

Say I have an array:

arr = [1,2,3,4,5]

and I want to output this using a simple counter and the modulus operator

1 
2
3
4 
5 
4
3 
2
1 
2 
3 
4 
5 
... 

Is this possible? I know that you can loop through an array and start over at the beginning by doing

arr[count % len(arr)]

but how do I just switch directions instead of going back to the beginning?

๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to iterate backwards in python
How to iterate backwards in Python | Replit
3 weeks ago - The reversed() function doesn't create a new, backward list. Instead, it returns an iterator that yields items from the original log_entries list, beginning with the last element.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ reverse an array in python
Reverse an Array in Python - Spark By {Examples}
May 31, 2024 - Related: In Python, you can use for loop to iterate iterable objects in reversing order and get them in backwards directions.
๐ŸŒ
Python Tutor
pythontutor.com โ€บ visualize.html
Python Tutor - Visualize Code Execution
The user can navigate forwards and backwards through all execution steps, and the visualization changes to match the run-time state of the stack and heap at each step. In this example, the user would see their custom LinkedList data structure getting incrementally built up one Node at a time via recursive calls to init() until the base case is reached when n==0. Despite its name, Python Tutor is also a widely-used web-based visualizer for Java that helps students to understand and debug their code.
Find elsewhere
๐ŸŒ
LeetCode
leetcode.com โ€บ problems โ€บ reverse-string
Reverse String - LeetCode
Reverse String - Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algorithm] with O(1) extra memory.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ for-loop
Python For Loop: Syntax and Examples [Python Tutorial]
Explore Python For loops to iterate over sequences and execute code efficiently. Learn to use for loops with lists, ranges, and dictionaries for better control.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python for loop in backwards
Python For Loop in Backwards - Spark By {Examples}
May 31, 2024 - Following are the examples of for loop in backwards # Example 1: Get the loop iteration in Backwards # Using reversed() print("Get the loop in backwards") for i in reversed(range(1,6)): # Example 2: Get the for loop in backwards using range() print("Get the loop in backwards") for i in range(6, 0, -1): # Example 3: Get the for loop in backwards using range() & len() # Initialize the list list=[10, 20, 50, 30, 40, 80, 60] print("Get the loop in backwards") for i in range(len(list) -1, -1, -1): # Example 4: Get the loop iterations in Backwards # using slicing list=[10, 20, 50, 30, 40, 80, 60] fo
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ backward-iteration-in-python
Backward iteration in Python
1 week ago - Python provides three common approaches: range() with negative step, slice notation [::-1], and the reversed() built-in function. Start from the last index and step backwards by -1 until index 0 ? days = ['Mon', 'Tue', 'Wed', 'Thu'] for i in ...
๐ŸŒ
Codemia
codemia.io โ€บ knowledge-hub โ€บ path โ€บ how_to_loop_backwards_in_python_duplicate
How to loop backwards in python?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
๐ŸŒ
Real Python
realpython.com โ€บ python-for-loop
Python for Loops: The Pythonic Way โ€“ Real Python
1 month ago - Learn how to use Python for loops to iterate over lists, tuples, strings, and dictionaries with Pythonic looping techniques.
๐ŸŒ
Amanxai
amanxai.com โ€บ home โ€บ all articles โ€บ backward for loop using python
Backward For Loop using Python | Aman Kharwal
October 13, 2021 - Below is how you can use a for loop over a list: list_ = ["Aman", "Kharwal", "Akanksha", "Hritika", "Shiwangi"] for i in list_: print(i) ... Now coming back to using a for loop backwards, Python has an inbuilt function known as reversed() that can ...
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ looping-in-reverse
Looping in reverse - Python Morsels
May 27, 2025 - To loop in the reverse direction, you can use Python's built-in reversed function: >>> colors = ["purple", "blue", "green", "pink", "red"] >>> for color in reversed(colors): ... print("I like", color) ...
๐ŸŒ
Klipper
klipper3d.org โ€บ G-Codes.html
G-Codes - Klipper documentation
STEPPER_BUZZ STEPPER=<config_name>: Move the given stepper forward one mm and then backward one mm, repeated 10 times.
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ how-to-reverse-a-list-in-python
How to Reverse a List in Python | Codecademy
In the first approach, reversed() is used with list() to create a new reversed list. In the second approach, reversed() is used directly in a for loop to iterate through elements in reverse order without creating a new list.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-reverse-string
Python Reverse String - 5 Ways and the Best One | DigitalOcean
August 3, 2022 - Python String doesnโ€™t have a built-in reverse() function. However, there are various ways to reverse a string in Python. ... Using Slicing to create a reverse copy of the string. Using for loop and appending characters in reverse order