a = " ".join(str(i) for i in range(10, 0, -1))
print (a)
Answer from user225312 on Stack Overflow
🌐
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
🌐
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.
🌐
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 - We set the end_position to -1 (rather than 0) since the range function goes to the end position, but doesn’t include it. Setting it to 0 would omit the first value. We set our increment to -1 to instruct Python to decrement by 1.
🌐
Quora
yourblogcoach.quora.com › Python-range-Function-reverse-increment-decrement
Python range() Function – reverse, increment, decrement - Your Blog Coach - Quora
So, if you want to decrement your sequence then you need to add step argument as a negative number. ... The python reversed() function you can use to make reverse order of sequence such as list and range().
Find elsewhere
🌐
PYnative
pynative.com › home › python › python range() explained with examples
Python range() Function Explained with Examples
March 17, 2022 - # Decrement range() using step # start = 30, stop = 20 # step = -2 for i in range(30, 20, -2): print(i, end=' ') # Output 30 28 26 24 22 Code language: Python (python) Run
🌐
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 article, we'll explore different methods to decrement a for loop in Python, each with its own advantages and use cases. Let's explore them one by one. In this example, the reversed() function is used with range(5) to create an iterator ...
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
🌐
CodeGym
codegym.cc › java blog › learning python › increment and decrement in python
Increment and Decrement in Python
November 11, 2024 - Another common way to decrement values is by using a while loop. This is particularly useful when you want to perform an action until a condition is no longer met. counter = 3 while counter > 0: print(counter) counter -= 1 · Here, the loop prints the value of counter until it reaches 0. With each iteration, counter -= 1 decreases the value by 1. A: Python emphasizes readability and simplicity, and the ++ and -- operators were deemed unnecessary for achieving this goal.
🌐
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 - Review the decrementing logic patterns. Large step values can cause unexpected iteration skips - know your data size vs range offsets. Avoid hard coded iteration counts - leverage range() and len() for programmatic control. The built-in Python range() function is an indispensable tool for controlling for loop iterations.
🌐
AskPython
askpython.com › home › decreasing for loops in python
Decreasing For Loops in Python - AskPython
March 9, 2023 - Reversing A String Using Decrementing For Loop · In this article, we have gone over the various features of “for” loops in python. Not only can we go through datasets from the first position to the last, but we can also do the reverse. Python allows us to iterate over elements from the very end to the front step by step as required using the range() function.
🌐
Guru99
guru99.com › home › python › python range() function: float, list, for loop examples
Python range() Function: Float, List, For loop Examples
August 12, 2024 - The start value is 15, the stop value is 5 and the step value is negative number i.e -1. With above inputs range() function will decrement the value from 15 onwards till it reaches the stop value , but here the difference is the last value will be stop + 1. Let us now work on the range() using ...
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › python › python_range_function.htm
Python range() Function
To decrement the sequence of numbers, you need to pass a negative integer value for the "step" parameter as demostrated in the below example. print("Even numbers in decreasing order:") for index in range(20, 11, -2): print(index) Following is ...
🌐
Dot Net Perls
dotnetperls.com › range-python
Python - range Examples - Dot Net Perls
March 13, 2024 - We can use range() to decrement a variable, to move downwards. We specify the "step" value as the optional third parameter of range.
🌐
iO Flood
ioflood.com › blog › python-range-function-guide-examples-syntax-and-advanced-uses
Python Range() Function Guide | Examples, syntax, and advanced uses
February 6, 2024 - For instance, range(1, 10, 2) yields a sequence of 1, 3, 5, 7, 9. Here, the sequence starts at 1, stops before 10, and increments by 2. ... Conversely, a negative step value can be used to decrement the sequence.
🌐
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.