Lists (list)
Going to make 30 separate variables to store 30 students’ names? name1, name2, name3… No! That’s what a list is for — an ordered box that holds lots of data in one variable.
How a list is made
Section titled “How a list is made”Square brackets [ ] plus comma-separated items:
Inputs (for input())
One value per line — read in order by input().
len(...) tells you the length of the list (how many items it holds). A list can store anything: text, numbers, even a mix.
List + loop = a powerful pair
Section titled “List + loop = a powerful pair”The for from module 03 works beautifully with a list — it walks each item one by one:
Inputs (for input())
One value per line — read in order by input().
Read it as: “for each friend in the friends list: greet them.” Whether the list held 3 names or 300, the code would stay the same. That’s the superpower. 💪
Missions
Section titled “Missions”A list of foods
+10 XP ✓ CompletedBuild a list called foods — with at least 3 of your favorite foods in it — and print it.
Inputs (for input())
One value per line — read in order by input().
Greet everyone
+10 XP ✓ CompletedWith for, greet every friend in the list on its own line: Hi, Aysel! and so on.
Inputs (for input())
One value per line — read in order by input().
How many are we?
+15 XP ✓ CompletedUse len() to find the length of the class list and print it like There are 5 students in the class.
Inputs (for input())
One value per line — read in order by input().
Next lesson: how do you grab a single item out of a list? The index — and Python counting from 0 again. Continue →