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
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python for loop in backwards
Python For Loop in Backwards - Spark By {Examples}
May 31, 2024 - # Get the loop iteration in Backwards # Using reversed() print("Get the loop in backwards") for i in reversed(range(1,6)): print(i) Yields below output. Python range() function is used to generate a sequence of numbers within a given range. You can use the range() function with a negative step value to implement the loop iterations from in backside rather than the front side...
Discussions

python - Loop backwards using indices - Stack Overflow
I am trying to loop from 100 to 0. How do I do this in Python? for i in range (100,0) doesn't work. For discussion of why range works the way it does, see Why are slice and range upper-bound exclu... More on stackoverflow.com
🌐 stackoverflow.com
Why isn't my loop iterating backwards in python?
Hint: Look up documentation on the ‘range’ function…does it actually do what you think it does given the two arguments you provided? Maybe you’re missing an argument? https://docs.python.org/3/library/stdtypes.html#range More on reddit.com
🌐 r/learnprogramming
13
0
March 8, 2023
How can I loop through an array forward and then backwards and then forwards and... etc with the modulus operator?
Given `n` is 1 less than the length of your array, you can increment and modulus some rotating index `i` against double `n` and then subtract `n`, take the absolute value and you get a bouncing number. It should be noted that you don't need to use any flags as suggested in other comments, but you do lose readability. Explanation: Take your example for an array of length 5, then `n=4`, `i` will rotate through values `[0, 1, 2, 3, 4, 5, 6, 7]` and subtracting `n` from each we get `[-4, -3, -2, -1, 0, 1, 2, 3]`, and the absolute values become `[4, 3, 2, 1, 0, 1, 2, 3]` which you can use to access the values at an index in your array. Try the following code: arr = [1, 2, 3, 4, 5] n = len(arr) - 1 i = n while True: curr_index = abs(i - n) print(arr[curr_index]) i = (i + 1) % (2 * n) and you will get output that looks like: 1 2 3 4 5 4 3 2 1 2 3 4 ... More on reddit.com
🌐 r/learnpython
5
1
September 9, 2021
loops - Traverse a list in reverse order in Python - Stack Overflow
How do I traverse a list in reverse order in Python? So I can start from collection[len(collection)-1] and end in collection[0]. I also want to be able to access the loop index. More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › backward-iteration-in-python
Backward iteration in Python - GeeksforGeeks
July 11, 2025 - a = [1, 2, 3, 4, 5] #Loop through the List # reverse order using slicing(::-1) for item in a[::-1]: print(item) # same logic written using List comprehension # [print(item) for item in a[::-1]] ... Using a while loop provides you control over ...
🌐
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) ...
🌐
Replit
replit.com › home › discover › how to iterate backwards in python
How to iterate backwards in Python | Replit
3 weeks ago - class CountDown: def __init__(self, ... 4 3 2 1 · You can make your own objects reversible by implementing the special __reversed__() method....
🌐
TutorialsPoint
tutorialspoint.com › backward-iteration-in-python
Backward iteration in Python
August 7, 2019 - We are using the range function ... us the following result − · Thu Wed Tue Mon · This method involves slicing the list which starts from the position -1 and go backwards till the first position....
Find elsewhere
🌐
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?

🌐
Medium
medium.com › becoming-a-better-software-developer › undetstanding-python-iterators-reversed-iteration-35f1c1d16196
Undetstanding Python Iterators: Reversed Iteration | by Saleem Latif | Becoming a better Software Developer | Medium
March 8, 2023 - >>> numbers = [1, 2, 3, 4, 5] >>> for number in reversed(numbers): ... print(number, end=" ") 5 4 3 2 1 · In the above example, we are reverse iterating over a list of numbers using the reversed() function.
🌐
Stack Abuse
stackabuse.com › bytes › traversing-a-list-in-reverse-order-in-python
Traversing a List in Reverse Order in Python
August 30, 2023 - Python has a built-in function called reversed() that returns a reverse iterator. An iterator is an object that contains a countable number of values and can be iterated (looped) upon. Here's a quick example: my_list = [1, 2, 3, 4, 5] for i in reversed(my_list): print(i)
🌐
Real Python
realpython.com › python-range
Python range(): Represent Numerical Ranges – Real Python
November 24, 2024 - The range parameters start, stop, and step define where the sequence begins, ends, and the interval between numbers. Ranges can go backward in Python by using a negative step value and reversed by using reversed().
🌐
JanBask Training
janbasktraining.com › community › python-python › how-do-i-reverse-a-list-or-loop-over-it-backwards
How do I reverse a list or loop over it backwards? | JanBask Training Community
June 4, 2025 - Python offers built-in features that make this process clean and readable. ... The reversed() function returns an iterator that yields the elements of the list in reverse order. my_list = [1, 2, 3, 4, 5] for item in reversed(my_list): print(item)
🌐
Delft Stack
delftstack.com › home › howto › python › loop backwards in python
How to Loop Backward Iteration in Python | Delft Stack
March 11, 2025 - Learn how to perform backward iteration in Python with various methods like range(), list slicing, and the reversed() function. This article provides clear examples and explanations to help you understand how to loop backward effectively. Perfect for beginners and experienced programmers alike, discover the best practices for iterating in reverse order.
🌐
Plain English
python.plainenglish.io › mastering-reverse-looping-in-python-a-comprehensive-guide-4a6380f623ca
Mastering Reverse Looping in Python: A Comprehensive Guide
March 25, 2024 - It is particularly useful when you need to process elements in reverse order or solve problems that require traversing a sequence backwards. In this article, we will dive deep into the world of reverse looping in Python. We will explore various techniques for implementing reverse looping, discuss their advantages and limitations, and provide practical examples to illustrate their usage.
🌐
TestMu AI Community
community.testmu.ai › ask a question
How to Loop Backwards in Python? - TestMu AI Community
December 8, 2024 - How can I loop backwards from 100 to 0 in Python using a backwards range python? I tried using for i in range(100, 0), but it doesn’t work as expected. How can I fix this to achieve a backward loop?
🌐
CodeRivers
coderivers.org › blog › iterating-backwards-python
Iterating Backwards in Python: A Comprehensive Guide - CodeRivers
April 24, 2025 - One common use case for iterating backwards is to search for a specific element in a sequence starting from the end. For example, if you have a list of file names and you want to find the last occurrence of a file with a certain extension. file_list = ["file1.txt", "file2.jpg", "file3.txt", ...
🌐
CodeGenes
codegenes.net › blog › how-to-loop-backwards-in-python
Mastering Backward Looping in Python — codegenes.net
# Loop backwards from 9 to 0 for i in range(9, -1, -1): print(i) In this example, the range() function starts at 9, stops at 0 (the - 1 is used because the stop value is exclusive), and has a step of -1, which means it counts down by 1 each time.