KS3 · Computer Science
Working with lists in Python
Seven days, seven variables? No need. One list holds the lot, in order, and you grab any day by its position. One catch: Python starts counting at 0.
Computing · Programming
Seven days, one list
Lists are one of the data structures you use to solve problems in code. Here's one in action: step through and watch which slot each index reaches.
Before you press Next, commit to a guess: what will print(days[1]) show?
1 days = ["Monday", "Tuesday",2 "Wednesday", "Thursday",3 "Friday", "Saturday",4 "Sunday"]5 print(days[1])6 print(days[4])7 day = int(input("Day number (1-7): "))8 print(days[day - 1])9 print(days[7])
Variables
Output
Step 1: One name, seven items. Python numbers the slots as it fills them: "Monday" goes into slot 0 and "Sunday" ends up in slot 6. Seven items, numbered 0 to 6. (It's split over four lines just to keep it readable. Still one list.)
Press Next to run one line at a time, and check each guess against the Output box.
Predict, then check
Think back to the program that crashed on days[7].
days holds seven items, so its indexes run 0 to 6. That's why days[7] crashed. Now the program removes "Sunday" from the list. What happens?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
One name, lots of items. And the first one lives at index 0.
What you need to know
- A list is a data structure: one name holding several related items, kept in order, one after another.
- To make one, write a name, then =, then the items inside square brackets with a comma between each.
- Text items are strings and need quotation marks, like "Monday"; whole numbers such as 12 go in without them.
Have a goThree things are going into a list: 42, Leeds and 7. Which one needs quotation marks round it?
Leeds
Leeds is text, so it's a string and needs quotes. 42 and 7 are whole numbers, so they go in bare; quoting them would turn them into text.
- Every item sits at a numbered position called its index, and Python starts that count at 0, not 1.
- So days[0] is the first item and days[1] the second: the index is one less than the place you'd say out loud.
Have a gopizza = ["cheese", "ham", "pineapple"]. Your friend is certain pizza[1] is cheese, "because one means first". What does pizza[1] really give?
"ham"
Cheese is at index 0. Your friend counted from 1, the way we count out loud, so they landed one item too early. (The pineapple debate is a separate argument.)
- Put an index in square brackets after the list's name to reach that item: print(days[4]) shows whatever sits at index 4.
- Ask for an index where no item sits, like days[7] in a seven-item list, and Python raises an IndexError.
- The index can be a calculation if it works out to a whole number: days[day - 1] turns a person's 1-to-7 into an index.
Have a goA quiz app lets you choose a question from 1 to 10, stored in q. The questions sit in a list called questions. What goes inside the square brackets?
q - 1, so questions[q - 1]
People count from 1 but the index starts at 0, so subtract 1 inside the brackets. questions[q] would land one question late, and q = 10 would ask for an index with no item.
- Selection (if / elif / else) picks one path, and each path can display a different item from the same list.
- A list is dynamic: it can grow or shrink as you add or remove items.
The big picture
A list keeps related items under one name, in order. Build one with a name, =, and the items in square brackets separated by commas; text needs quotation marks, whole numbers don't. The first item is at index 0, so days[1] is the second. An index can be a calculation like days[day - 1] if it works out to a whole number, and an index with no item raises an IndexError. Selection can show a different item on each path, and a list can grow or shrink.
Key points
Worked example
Problem
A game stores four high scores: scores = [12, 7, 15, 9]. Then the program runs n = 3. What does each line display? (a) print(scores[1]) (b) print(scores[n - 1]) (c) print(scores[4])
⚠ Watch out
Counting the first item as position 1. It's tempting, because that's how you count out loud, but days[0] is Monday and days[1] is Tuesday. The same slip makes days[7] look like Sunday in a seven-day list; really the last index is 6, and days[7] raises an IndexError.
Memory hook
The index counts steps from the start. The first item is zero steps away, so it lives at index 0.
Check yourself
No peeking: pets = ["cat", "dog", "rabbit", "hamster"]. What does print(pets[3]) display, which index holds "cat", and what would print(pets[4]) do?
Flashcards
(14)What is a list?
What's the pattern for creating a list in Python?
Which list items need quotation marks?
Can one list be written across several lines?
What is an index?
What index does the first item in a Python list have?
A list holds 7 items. What is the index of the last one?
How do you display the item at index 4 of a list called days?
What happens if you use an index where the list holds no item?
Can an index be a calculation, like days[day - 1]?
What goes wrong in ["Hull" "Bath"]?
How can selection be used with a list?
Why is a list called a dynamic data structure?
A list of seven days has one day removed. How many items does it hold now?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore KS3 Computer Science topics
How this lesson was checked. This KS3 Computer Sciencelesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 27 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.