← All lessons

for: repeat over a collection

Sign in · Sign up

Lesson 3.1

for goes through each item, one after another:

for letter in "Mia":
    print(letter)

It reads like this: for each letter in the word "Mia" print it. On every step letter holds the next letter, and you make up the name letter yourself — any name will do.

Strings and ready-made lists are looped the same way:

for item in [1, 2, 3]:
    print(item)

The word is set by the check. Print each of its letters on a new line.

Hint

for goes item by item and stops on its own when the items run out.

The word is already set by the check — write only the loop. Inside, the letter is printed on its own line.