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 - How to decrement (for example by ... 4 e.t.c. You can easily achieve this by using the range() function, with the range you can decrement the for loop index with a negative step value....
🌐
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 ...
🌐
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 have applied all the values inside the range() function in for loop. The start index is set as 10, the stop index is set as 0, and the step is set as -2, which will decrement the value by 2 at each iteration until 0.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-decrement-a-python-for-loop
How to Decrement a Python for Loop - GeeksforGeeks
July 23, 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.
🌐
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 - We can even specify the “step” ... ... For example, if the value of start = 0 and stop = length of the required list and step= 2, then the for loop will iterate over every second element in the entire list....
🌐
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 - # The Python range() Function Explained range( start = # The starting number , stop = # The end number , step = # The number by which to increment ) Let’s break these parameters down a little further: ... In order to decrement a for loop in Python, we can make creative use of this function.
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
🌐
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....
🌐
Java2Blog
java2blog.com › home › python › how to decrement for loop in python
Python for loop decrement - Java2Blog
October 28, 2021 - Since we usually decrement a value in the for loop to do something in reverse order, we use this function to reverse the given sequence directly. The range() function within the for loop can be passed as a parameter to the reversed() function to implement the desired output.
🌐
CodeVsColor
codevscolor.com › how to decrement a for loop in python - codevscolor
How to decrement a for loop in Python - CodeVsColor
September 12, 2021 - For example, let me change the above example to decrement: ... It will start at 18 and ends at 9 with step level -2. It will print: ... It starts at 18, decrement 2 on each step and before 9 is reached it stops, i.e. it stops at 10.
🌐
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.
🌐
PYnative
pynative.com › home › python › python range() explained with examples
Python range() Function Explained with Examples
March 17, 2022 - ... Use a negative step value in a range() function to generate the sequence of numbers in reverse order. For example, range(5, -,1, -1) will produce numbers like 5, 4, 3, 2, and 1. I.e., you can reverse a loop by setting the step argument of ...
🌐
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!")...
🌐
CodeGym
codegym.cc › java blog › learning python › increment and decrement in python
Increment and Decrement in Python
November 11, 2024 - In this example, range(3) generates numbers from 0 to 2. Each iteration, the loop variable i is incremented automatically. Just like incrementing, Python lacks the -- operator for decrementing. But no worries!
🌐
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.
🌐
ImportPython
importpython.com › home › playing with numbers: mastering the art of decrementing in python
How To Decrement In Python: Tips And Techniques
March 12, 2024 - Decrementing works with floating-point numbers just as it does with integers. For example, number -= 0.5. ... To decrement each element in a list, you can use a loop: numbers = [10, 20, 30] for i in range(len(numbers)): numbers[i] -= 1