@Massifox already pointed out the -1 step but I can add more context. The optional third parameter in range() is step. If you did range(1, 20, 2)
it would print 2, 4, 6, ..., 18
because you specified steps of 2.
For your example, you started 20, and incremented until you hit 1, but that will never happen, so nothing gets printed, so you specify a step of -1 like range(20, 1, -1)
, so that it will step backwards each iteration printing 20, 19, ..., 2
(second parameter is exclusive).
When you tried this
for x in range(1,20):
count = 20
count -= 1
print(count)
You created a temp variable named count, initialized to 20, subtracted one from it, and then printed it, and the result was the 19's you were getting. Everything inside the for loop will be a temporary variable and cannot affect the iteration of the for loop. LMK if this is too verbose.