For Loops

Attention: Our videos have subtitles in all partner languages. You can switch on subtitles in the youtube player by clicking the gear wheel and selecting your preferred language.

In this section, we introduce another type of loop which is great in combination with lists. We show you how to use it and when to use it. The for loop is everywhere. It reduces the repetition of the code and gives you full control over the loops. It allows for controlled cycles of the code, giving you the possibility to build smaller and refined pieces of code.

Storing personal information
Create a dictionary called person with two key-value pairs: "name": "Alice" "age": 25 Print the person's name and age.
Solution
 # Create a dictionary with person information
person = {
    "name": "Alice",
    "age": 25
}

# Print the person's information
print("Name:", person["name"])
print("Age:", person["age"])