a = " ".join(str(i) for i in range(10, 0, -1))
print (a)
Answer from user225312 on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-decrement-a-python-for-loop
How to Decrement a Python for Loop - GeeksforGeeks
July 23, 2025 - The loop prints each value in descending order. In this example, the range(4, -1, -1) function generates a sequence starting from 4 and decrementing by 1 until reaching -1 (exclusive).
Discussions

How to decrement using a for or while loop?
I am new to Python programming. The code below works just fine but I want to decrement the initialized amount of tickets which is 100 until it hit zero tickets. For instance, below if you run my code, I enter the input of three; it outputs the difference of the initialized value of 100 and the result is 97 tickets. I want to loop ... More on teamtreehouse.com
๐ŸŒ teamtreehouse.com
7
April 9, 2019
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
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
python - how to decrement the loop - Stack Overflow
I'm wondering if there is any possible way to decrement the loop in python? Iโ€™ve searched on many websites but I didnโ€™t find anything helpful. For example, I was thinking about this simple function... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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 ...
๐ŸŒ
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 - Generally, we increment a for loop, meaning we loop over our sequence in increasing order. For example, looping over the list containing [0,1,2,3] would start at 0 and increment by 1, through to the end of the list.
๐ŸŒ
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....
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ decreasing for loops in python
Decreasing For Loops in Python - AskPython
March 9, 2023 - Hence, string reversals can be easily done using these two statements in Python. The syntax for this purpose will have the following changes: ... In this case, the value of i will start from the very last position. N is the length of the data set (say, for example, a list), hence the last element will be situated at the (N-1)th position. The first element is situated at the 0th position, hence we had to mention -1 as the end because the for loop stops looping at the (stop+1)th position.
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ learning python โ€บ increment and decrement in python
Increment and Decrement in Python
November 11, 2024 - This is particularly useful when ... 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 -- ...
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ how to decrement for loop in python
Python for loop decrement - Java2Blog
October 28, 2021 - It can loop through different iterables also in Python. We need to decrement a for loop when we wish to execute something in reverse order. Python does not make use of the decrement operator in the for loop.
๐ŸŒ
CodeSpeedy
codespeedy.com โ€บ home โ€บ python for loop decrementing index
Python for loop decrementing index - CodeSpeedy
July 21, 2019 - By making the step value negative it is possible to decrement the loop counter. ... As it is observed, initial value of x is 10 and it goes on decrementing till 0 with the step value -2. In for loop, index is by default incremented by 1.
๐ŸŒ
Team Treehouse
teamtreehouse.com โ€บ community โ€บ how-to-decrement-using-a-for-or-while-loop
How to decrement using a for or while loop? (Example) | Treehouse Community
April 9, 2019 - Enter โ€˜Yโ€™ for yes and โ€˜Nโ€™ for no โ€) if exit_while_loop == Y: break ... Thank you Christian. I wanted to make my code a slight different because I did not want to copy yours and find the root cause why code was executing the way I wanted it to. Last night, I was able to loop successfully but I could not get it to decrement correctly.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ decrement a loop python
How to Decrement a Loop in Python | Delft Stack
March 11, 2025 - This tutorial demonstrates how to decrement a loop in Python. Learn to effectively utilize decrementing for loops and while loops, complete with clear examples and explanations. Whether you're a beginner or an experienced coder, this guide will enhance your understanding of decrementing loops ...
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
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ increment and decrement operators in python
Increment and Decrement Operators in Python - Scaler Topics
March 12, 2024 - When coupled with increment and decrement operators, it becomes a dynamic mechanism for altering numeric values. Consider the following example: In this example, we can see that the loop starts at 5 and declines by 1 until it reaches 1, demonstrating the decrement operator's role in influencing loop behaviour. When incrementing a variable in Python via assignment, the language's simplicity is evident.
๐ŸŒ
Besant Technologies
besanttechnologies.com โ€บ home โ€บ blogs โ€บ general โ€บ python loops
Python Loops | Loops in Python | Python Tutorials For Beginners
October 8, 2021 - For loop in python is used to iterate of any sequence such as list or a string. For loop which is used to executing a block of statements or code several times until the given values are iterate able. ... We need to assign a value with list value to be iterating value rather than conditional value are not assigned. ... We need to set a variable to passed in the statement and which are executed till the iterating values . ... 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 list value.
๐ŸŒ
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 ...
๐ŸŒ
LearnPython.com
learnpython.com โ€บ tags โ€บ loop
Loop | LearnPython.com
August 22, 2022 - Itโ€™s easy! You can do it with a simple for loop, and Iโ€™ll show you how. Unlike other programming languages (such as C++) Python has no decrement operator (i.e. similar to the -- in C++). In Python, we state the beginning and the end of the iteration with the number of steps in between.
๐ŸŒ
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!")...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 60367496 โ€บ how-to-decrement-the-loop
python - how to decrement the loop - Stack Overflow
Python doesn't have the same syntax as the for loop in C or other languages. Kind of requires some getting used to at first. If you want to have an array index, for instance, that increments or decrements by variable amounts on each iteration, you just declare them above the for statement, and in the loop increment them as you have it above.