python for loop decreasing code example
Example 1: decreasing for loop python
for i in range(5,0,-1):
print(i)
#Prints: 5,4,3,2,1
#Inclusive of 5, not inclusice of 0. "-1" denotes the decrease
Example 2: how does the range function work in python when counting down
range(4)
#considers numbers 0,1,2,3
range(1, 4)
#considers numbers 1,2,3
range(1, 4, 2)
#considers numbers 1,3
range(4, 1, -1)
#considers numbers 4,3,2