I am trying to loop from 100 to 0. How do I do this in Python?
for i in range (100,0)
doesn't work.
To reverse for loop in Python just need to read the last element first and then the last but one and so on till the element is at index 0. You can do it with the range function, List Comprehension, or reversed() function.
Try range(100,-1,-1)
, the 3rd argument being the increment to use (documented here).
("range" options, start, stop, step are documented here)
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