a = " ".join(str(i) for i in range(10, 0, -1))
print (a)
Answer from user225312 on Stack Overflow
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › perform for loop decrement in python
Perform For Loop Decrement in Python - Spark By {Examples}
May 31, 2024 - Python range() function is used ... If you want to use range() with decrement for a loop in Python, you can set the step parameter to a negative value....
🌐
LearnPython.com
learnpython.com › blog › decrement-in-python-for-loop
How to Decrement a Python for Loop | LearnPython.com
August 22, 2022 - The previous example provides some insight on how to decrement in a Python for loop using range(). We can apply it in a straightforward manner by setting the start and the end parameters so that end < start and there’s a negative step value. Let's try! >>> for i in range(9, -1, -1): ...
🌐
Real Python
realpython.com › lessons › range-decrementing
Decrementing With range() (Video) – Real Python
00:19 Think about it like this. If I ask you to count from 10 to 20, but down by 2, what numbers would you say? None. Let’s give this a try. I’ll say for i in range(10, -6, -2): and print(i).
Published   October 15, 2019
🌐
AskPython
askpython.com › home › decreasing for loops in python
Decreasing For Loops in Python - AskPython
March 9, 2023 - Hence, the loop will move from ... Control flow tools in python. Using the range() function we can specify the position from where the iteration should start and where it should end....
🌐
Python Pool
pythonpool.com › home › blog › 4 ways to decrement for loop in python
4 Ways to Decrement for loop in Python - Python Pool
January 3, 2024 - In this example, we will use the start index and stop index, decreasing the value in the for loop. We will set the start index’s value greater than the stop index so that the value will be decremented individually at each iteration.
🌐
datagy
datagy.io › home › python posts › how to decrement a for loop in python
How to Decrement a For Loop in Python • datagy
September 20, 2022 - Let’s load a Python list and ... 'Jane'] We can loop over this list in reverse order by making the starting position the last index and decrementing by 1. Let’s see how we can do this: # Looping Over a List in Reverse ...
Find elsewhere
Top answer
1 of 5
18

I would like to go over the range() function yet again through the documentation as provided here: Python 3.4.1 Documentation for range(start, stop[, step])

As shown in the documentation above, you may enter three parameters for the range function 'start', 'stop', and 'step', and in the end it will give you an immutable sequence.

The 'start' parameter defines when the counter variable for your case 'i' should begin at. The 'end' parameter is essentially what the size parameter does in your case. And as for what you want, being that you wish to decrease the variable 'i' by 1 every loop, you can have the parameter 'step' be -1 which signifies that on each iteration of the for loop, the variable 'i' will go down by 1.

You can set the 'step' to be -2 or -4 as well, which would make the for loop count 'i' down on every increment 2 down or 4 down respectively.

Example:

for x in range(9, 3, -3):
    print(x)

Prints out: 9, 6. It starts at 9, ends at 3, and steps down by a counter of 3. By the time it reaches 3, it will stop and hence why '3' itself is not printed.

EDIT: Just noticed the fact that it appears you may want to decrease the 'i' value in the for loop...? What I would do for that then is simply have a while loop instead where you would have a variable exposed that you can modify at your whim.

test = 0
size = 50
while (test < size)
    test += 1
    if (some condition):
        test -= 1
2 of 5
6

For such a construct, where you need to vary the loop index, a for loop might not be the best option.

for <var> in <iterable> merely runs the loop body with the <var> taking each value available from the iterable. Changing the <var> will have no effect on the ensuing iterations.

However, since it is usually tricky to work out the sequence of values i will take beforehand, you can use a while loop.

i = 0
while i < size:
    if condition:
        ...
        i -= 1
    else:
        ...
        i += 1
🌐
Java2Blog
java2blog.com › home › python › how to decrement for loop in python
Python for loop decrement - Java2Blog
October 28, 2021 - The step parameter tells how much to increment or decrement between the values in the series. To decrement a value in the for loop, the start value should be greater than the stop value, and the step parameter should be a negative integer.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-decrement-a-python-for-loop
How to Decrement a Python for Loop - GeeksforGeeks
July 23, 2025 - Python’s for loop is commonly used to iterate over sequences like lists, strings, and ranges. However, in many scenarios, we need the loop to count backward. Although Python doesn't have a built-in "decrementing for loop" like some other languages (e.g., for(int i = n; i >= 0; i--) in C++), there are several effective ways to achieve the same behavior in Python.
🌐
CodeVsColor
codevscolor.com › how to decrement a for loop in python - codevscolor
How to decrement a for loop in Python - CodeVsColor
September 12, 2021 - Python program to decrement a for loop. Learn how to do this by using range() and by using reversed() methods.
🌐
Delft Stack
delftstack.com › home › howto › python › decrement a loop python
How to Decrement a Loop in Python | Delft Stack
March 11, 2025 - The while loop continues to execute as long as count is greater than 0. Inside the loop, we print the current value of count and then decrement it by 1 using count -= 1. This method is particularly useful when the decrementing condition is more ...
🌐
CodeSpeedy
codespeedy.com › home › python for loop decrementing index
Python for loop decrementing index - CodeSpeedy
July 21, 2019 - As seen in previous example only stop value is given and it starts from 0(by default) also its step is 1(by default) If the user wants to decrement the index value inside for loop then he/she should make the step value negative.
🌐
GeeksforGeeks
geeksforgeeks.org › decrement-in-while-loop-in-python
Decrement in While Loop in Python - GeeksforGeeks
February 13, 2023 - Firstly a variable is initialized ... aforementioned variable is greater than 0. Then inside the loop body, the variable's value is displayed, and the variable's value is decremented by 1. Hence upon each iteration, the value of variable ...
🌐
PYnative
pynative.com › home › python › python range() explained with examples
Python range() Function Explained with Examples
March 17, 2022 - You can use the following two ways to get the reverse range of numbers in Python. ... Use a negative step value in a range() function to generate the sequence of numbers in reverse order.
🌐
Llego
llego.dev › home › blog › using range() in for loops to control iterations in python
Using range() in for Loops to Control Iterations in Python - llego.dev
May 26, 2023 - When using range() for controlled iteration, be mindful how start, stop, and step values are specified to properly increment or decrement the sequence.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › range() in for loop in python
range() in for loop in Python - Spark By {Examples}
May 31, 2024 - Note that here, I have used the ... # Output: # 1,3,5,7,9, To decrement the range of values in for loop, use the negative value as a step parameter....
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to increment for loop in python
How to Increment For Loop in Python - Spark By {Examples}
May 31, 2024 - Python for loop is usually increment by 1 value however sometimes you would be required to increment 2, 3, 4 e.t.c. You can easily achieve this by using the range() function, with the range you can increment the for loop index with a positive ...