Codzy

For loops

A for loop repeats a block of code for each item of a sequence: a list, a string or a series of numbers.

range(n) produces the numbers from 0 to n-1. range(a, b) starts at a and stops before b. As with if, the repeated block is indented by 4 spaces.

for i in range(3):
    print("Round", i)

for letter in "Hi":
    print(letter)

Start the lesson