loop from 10 to 5 in python

In Python, you can use the range() function with the decrement step size of -1 inside a for loop to iterate over a sequence of numbers in reverse order from 10 to 5. Here's how you can do it:

main.py
for num in range(10, 4, -1):
    print(num)
44 chars
3 lines

In the range() function, the first argument represents the starting number of the sequence, the second argument represents the ending number of the sequence (exclusive), and the third argument represents the step size. By setting the step size to -1, we make the sequence count down from 10 to 5. Then, we use a for loop to iterate over each number in the sequence and print it to the console.

gistlibby LogSnag