Skip to content

Repeating with for

Read · 1 of 5

range gives the numbers to count through

for i in range(1, 4): runs the indented lines with i = 1, then 2, then 3. The end number (4) is not included.

range(5) is 0 to 4. range(0, 10, 3) counts in steps of 3: 0, 3, 6, 9.