Locked lesson.
About this lesson
For loops are used to loop through things like lists or groups of data.
Exercise files
Download this lesson’s related exercise files.
10 - Python For Loops (1).docx57.2 KB 10 - Python For Loops SOLUTION.docx
55.6 KB
Quick reference
Python For Loops
For loops are used to loop through things like lists or groups of data.
When to use
Use them whenever you have any sort of list of items that you need loop through and grab individual items from.
Instructions
Given a List:
names = ["John", "Tina", "Joe"]
Create a list:
for name in names:
print(name)
Be sure to indent all lines in a for loop (except the first declaration line) using the tab key on your keyboard.
Hints & tips
- for name in names:
- indent all lines of a for loop except the first one
- use an f-string to add text: f'Hello there {name}...'
Lesson notes are only available for subscribers.