a = " ".join(str(i) for i in range(10, 0, -1))
print (a)
Answer from user225312 on Stack Overflow
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ decrement-in-python-for-loop
How to Decrement a Python for Loop | LearnPython.com
August 22, 2022 - We can also set the step parameter to some other value (like -3) and the for loop will decrement by 3 instead of 1. Let's modify the previous example and output the results: >>> for i in range(9, -1, -3): ... print(i) ... 9 6 3 0 ยท We can also ...
Discussions

Is there a way to change the value of range in a for loop?
It's hard to give feedback if you don't tell us what you want to do. More on reddit.com
๐ŸŒ r/learnpython
26
10
June 20, 2023
Python for loop decrementing index - Stack Overflow
So I wrote a for loop like this: for i in range(size): if(.....) .... i-=1 else: .... I try to decrease the index by 1 if it is inside the if statement, but apparently I can't do t... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Decreasing for loops in Python impossible? - Stack Overflow
It's telling, though, that the ... between Python 2.3 and 2.4 2013-08-26T21:33:15.753Z+00:00 ... reversed(range(10)) can't possibly output 4 through 0. Perhaps you meant range(5)? 2019-12-29T01:07:54.197Z+00:00 ... 0 is conditional value when this condition is true, loop will keep executing.10 is the initial value. 1 is the modifier where may be simple decrement... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How can I increment i with an additional value within a for loop?
Firstly, the i += 1 part of your code does nothing. Second, the range function can take up to three arguments. When you pass all three, the first is the starting number, the second is the last number (but remember that Python uses half-open intervals), and the last is the step. So you'd do for i in range(0, 4, 2): print(i) More on reddit.com
๐ŸŒ r/learnpython
11
2
May 27, 2022
๐ŸŒ
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 - How to decrement (for example by 2) for loop in Python? usually, Python for loop is incremented by 1 value however sometimes you would be required to decrement by 1, 2, 3, 4 e.t.c. You can easily achieve this by using the range() function, with ...
๐ŸŒ
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
๐ŸŒ
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 - # Loading a Sample Python List names = ['Nik', 'Kate', 'Evan', 'Kyra', '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 ...
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ decreasing for loops in python
Decreasing For Loops in Python - AskPython
March 9, 2023 - Hence, the loop will move from the 0th position to the (N-1)th position, where N is the length of the dataset such as array, list, or tuple. Suggested: 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 - A For Loop is used to iterate over the sequence: a list, a tuple, a dictionary, a set, or a string. There is no decrement operator in Python. We can only decrement the value in Python, but there is no such operator in Python.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-decrement-a-python-for-loop
How to Decrement a Python for Loop - GeeksforGeeks
April 14, 2025 - In this example, the range(4, -1, -1) function generates a sequence starting from 4 and decrementing by 1 until reaching -1 (exclusive). The for loop iterates over this sequence, printing each value in reverse order.
Find elsewhere
๐ŸŒ
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.
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
๐ŸŒ
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 - In the upcoming example, this would ... 0: # Displaying the value of n for that iteration print(n) # Decrementing the value by 1 n = n - 1 print("Loop Ends!")...
๐ŸŒ
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 - Sometimes, you may want to decrement ... to do it using a for loop: ... In this example, range(20, 0, -2) creates a sequence that starts at 20 and decrements by 2 until it reaches 0....
๐ŸŒ
Besant Technologies
besanttechnologies.com โ€บ home โ€บ blogs โ€บ general โ€บ python loops
Python Loops | Loops in Python | Python Tutorials For Beginners
October 8, 2021 - We no need to set a decrement /increment value based the needs of the function or statement the statement of loop is based on the String value. ... Range () function is to generate a sequence of numbers from the start value to stop value based on step.
๐ŸŒ
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....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-loop-through-a-range
Python - Loop Through a Range - GeeksforGeeks
1 week ago - Below is the syntax: range(start, stop, step) start: value at which the range starts (inclusive). stop: value at which the range stops (exclusive). step: increment or decrement for each iteration (default is 1).
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ python range() explained with examples
Python range() Function Explained with Examples
March 17, 2022 - Python range() returns the sequence of numbers starting from a given start integer to a stop integer, which we can iterate using a for loop