--Originally published at Just A Turtle Coding.
Ranges are used a lot in for loops, but understanding them is key to knowing how to program.
A range basically tells Python from which number to which number it should read.
As long as the variable is a number, you can use it in a range.
for x in range (8)
print(x)
it would print 0,1,2,3,4,5,6,7,8 since Python starts from 0.
You could use another notation to tell Python how to read the range.
for x in range (A,B,C)
where A is the start number, B is the end number, and C is the period in which Python should read it. If you want a number to go negatively, you have to use C value as -1. It should look like this:
for x in range (0,-10,-2)
print(x)
0,-2,-4,-6,-8,-10
Here’s more info about the topic: