I could be wrong (just let me know and I'll delete the question) but it seems python won't respond to
for n in range(6,0): print n
I tried using xrange and it didn't work either. How can I implement that?
Use the Reversed Function to Decrement a For Loop in Python The Python reversed() function takes an iterable object, such as a list, and returns a reversed object.
The Python break statement immediately terminates a loop entirely. Program execution proceeds to the first statement following the loop body. The Python continue statement immediately terminates the current loop iteration.
You can stop an infinite loop with CTRL + C .
for n in range(6,0,-1): print n # prints [6, 5, 4, 3, 2, 1]
This is very late, but I just wanted to add that there is a more elegant way: using reversed
for i in reversed(range(10)): print i
gives:
4 3 2 1 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With