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

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
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
While loop with increment and decrement?
x += 0 and y -= 0 doesn't change the value of X and y so your while loop never terminates. Think about -1 * weekday. More on reddit.com
🌐 r/learnpython
13
5
April 11, 2017
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
🌐
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).
🌐
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.
🌐
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.
🌐
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.
🌐
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 ...
🌐
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.
🌐
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.
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
🌐
Real Python
realpython.com › lessons › range-decrementing
Decrementing With range() (Video) – Real Python
01:45 That looks like this. for i in reversed() and I’ll pass in range(5). print(i). The range() function will give us a list from 0 to 4, and reversing that will allow us to iterate from the last value in the list down to the first. 02:11 You could also accomplish this by just using the range() function without reversed(), but we’ve included this here to show you another way you might see iteration done. Become a Member to join the conversation. ... Get a Python Cheat Sheet (PDF) and learn the basics of Python, like working with data types, dictionaries, lists, and Python functions:
Published   October 15, 2019
🌐
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 ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › g-fact-21-increment-and-decrement-operators-in-python
Increment += and Decrement -= Assignment Operators in Python - GeeksforGeeks
We can adjust start and stop with help of Python decrement and increment operators. In this example, the Python increment operator (+=) is demonstrated by incrementing the variable count by one. Additionally, the range() function is utilized in a for loop to showcase both incrementing and decrementing loops, providing a Pythonic alternative to traditional increment and decrement operators found in some other programming languages.
Published   April 30, 2024
🌐
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.
🌐
Python.org
discuss.python.org › ideas
Increment, decrement... Can we have inc(), dec() functions in Python? feature request :) - Page 2 - Ideas - Discussions on Python.org
December 4, 2022 - No. It is nothing like next. I’ve already given code using Python syntax that shows how Pascal inc and dec work. Unfortunately you can’t run that code, because they are don’t work in Python, but you can surely follow the input and the expected result. Let’s try again: x = 15 inc(x) # There is NO ASSIGNMENT HERE. assert x == 16 # But like magic, x has a new value!