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

days[0]="Monday"days[1]="Tuesday"days[2]="Wednesday"days[3]="Thursday"days[4]="Friday"days[5]="Saturday"days[6]="Sunday"

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.)

1 / 6

Press Next to run one line at a time, and check each guess against the Output box.

Step 1 of 6: 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.).

Check your thinking

Which snack is snacks[1]?

A new list: snacks = ["crisps", "apple", "flapjack", "banana", "yoghurt"]

Which of these is closest to what you think right now?
How sure are you?

Your turn

Build two lists from scratch

Here's one that's already done, so you can see the shape: colours = ["red", "green", "blue"]

Write two lines of Python. Line 1 creates a list called pets that holds the text items cat, dog and rabbit. Line 2 creates a list called ages that holds the whole numbers 11, 12 and 14. [5 marks]

0 words · your answer stays on this page and is not sent anywhere.

Debug it

The playlist plays the wrong song

This program should ask for a track number from 1 to 5 and play that track. But typing 1 plays "Echo" (the second track), and typing 5 crashes with an IndexError. Which line is wrong?

A program with one bug — which line goes wrong?

Lists + selection

Finish the seasons program

This program asks for a month number (1 to 12), shows the month's short name, then shows its season. In this program, winter is months 12, 1 and 2; spring is 3 to 5; summer is 6 to 8; and autumn is 9 to 11. Choose the missing lines.

  1. months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]Twelve items, so the indexes run 0 to 11.
  2. seasons = ["winter", "spring", "summer", "autumn"]Four items: winter at index 0, autumn at index 3.
  3. month = int(input("Month number (1-12): "))We're assuming the person types a whole number from 1 to 12, as asked.
  4. missing step
Which line is step 4?

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

1A list stores several related items under one name, in a fixed order, one after another.
2Pattern: name = [item, item, item]. Strings need quotation marks; integers don't.
3The first item is at index 0, so a seven-item list uses indexes 0 to 6.
4Using an index with no item there, like days[7] in a seven-item list, raises an IndexError.
5To turn a person's count from 1 into an index, subtract 1 inside the brackets: days[day - 1].
6A list is dynamic: it grows when items are added and shrinks when items are removed.

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?
A data structure that stores several related items under one name, kept in order, one after another.
What's the pattern for creating a list in Python?
A name, then =, then the items inside square brackets with commas between them, e.g. days = ["Monday", "Tuesday"].
Which list items need quotation marks?
Text items (strings), e.g. "cat" or 'cat'. Whole numbers (integers) such as 11 don't.
Can one list be written across several lines?
Yes. Splitting the items over a few lines just keeps it readable; it's still one list.
What is an index?
The position of an item in a list, written as a whole number in square brackets after the list's name.
What index does the first item in a Python list have?
0. Python indexing is zero-based.
A list holds 7 items. What is the index of the last one?
6, which is one less than the number of items.
How do you display the item at index 4 of a list called days?
print(days[4])
What happens if you use an index where the list holds no item?
Python raises an IndexError. With nothing in the program to handle it, the program stops at that line.
Can an index be a calculation, like days[day - 1]?
Yes, as long as it works out to a whole number (an integer). Even 2.0 won't do, because it isn't an integer.
What goes wrong in ["Hull" "Bath"]?
The comma is missing between "Hull" and "Bath". Items in a list need a comma between each pair.
How can selection be used with a list?
An if / elif / else statement checks conditions to choose a path, and each path can display a different item from the list.
Why is a list called a dynamic data structure?
It can grow or shrink as you add or remove items, so its length can change while the program runs.
A list of seven days has one day removed. How many items does it hold now?
Six. The list shrinks by one, so its indexes now run 0 to 5.

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 posted

More KS3 Computer Science topics

See the full KS3 Computer Science curriculum →

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.

Helpful guides for parents and students