🐍 Python for kids · Class 5 · Lesson 10 of 18 · Free
Lists – Storing Many Values
⏱ About 25 minutes · ▶ run real Python here — nothing to install · no sign-in
In this lesson you will
- Make a list and read items with index numbers.
- Add items with append() and count them with len().
- Loop over a list and find its sum, max and min.
Your class has 40 students. Would you make 40 variables, like name1, name2, name3? That is a lot of typing! A list keeps all 40 names in one place.
What is a list in Python?
A list is one variable that holds many values, in order. Think of a tiffin box with many compartments.
You write a list with square brackets [ ]. Commas separate the items.
A list can hold words, numbers, or both. print() shows the whole list at once.
['mango', 'banana', 'guava'] [78, 92, 65, 88] Number of fruits: 3
💡 len() counts the items in a list, just like it counted letters in a string.
How do I get one item from a list using its index?
Every item has a position number called an index. Python starts counting from 0, not 1.
So fruits[0] is the first item and fruits[1] is the second. This is the same as range(), which also starts at 0.
A minus index counts from the end. fruits[-1] is always the last item.
▶fruits = ["mango", "banana", "guava"]2first = fruits[0]3last = fruits[-1]4print("First fruit:", first)5print("Last fruit:", last)6fruits[1] = "apple"7print(fruits)
No variables yet.
▌✏️ Change this code and run it yourself
First fruit: mango Last fruit: guava ['mango', 'apple', 'guava']
💡 fruits[1] = "apple" swaps the second item. Lists can be changed after you make them.
How do I add items to a list with append()?
append() adds a new item to the end of a list. The list grows by one each time.
You can start with an empty list [ ] and fill it bit by bit. This is very useful with input() in a loop.
Below, three friends tell us their favourite cricketer, and we collect the answers.
▶players = []2for i in range(3):3 name = input("Favourite cricketer: ")4 players.append(name)5print(players)6print(f"We collected {len(players)} names.")
No variables yet.
▌✏️ Change this code and run it yourself
Favourite cricketer: Virat Favourite cricketer: Rohit Favourite cricketer: Smriti ['Virat', 'Rohit', 'Smriti'] We collected 3 names.
How do I loop over every item in a list?
A for loop can walk through a list directly. Each time round, the loop variable becomes the next item.
You do not need range() or index numbers for this. Python hands you each item in order.
Read it like English: for each snack in the snacks list, print it.
▶snacks = ["samosa", "idli", "poha", "vada pav"]2for snack in snacks:3 print(f"I like {snack}.")4print("That is all the snacks!")
No variables yet.
▌✏️ Change this code and run it yourself
I like samosa. I like idli. I like poha. I like vada pav. That is all the snacks!
How do I check if something is in a list?
The word in asks: is this value somewhere in the list? The answer is True or False.
You can use it inside an if, just like a comparison. not in asks the opposite question.
Here we check whether a name is on the class picnic list.
Your name: Diya You are on the picnic list! True
How do I sort a list and find the total, highest and lowest?
Python has ready-made helpers for lists of numbers. sum() adds them all, max() finds the biggest, and min() finds the smallest.
sort() puts the list in order, from smallest to largest. It changes the list itself.
These save you from writing long loops for common jobs.
Total runs: 171 Highest score: 78 Lowest score: 6 Sorted: [6, 12, 30, 45, 78]
💡 Words can be sorted too. They go in A to Z order.
🤔 Predict the output
Think like Python: read the code and choose what it prints. You get the reason straight away.
Question 1. What does this print?
colours = ["red", "green", "blue"] print(colours[1])
Question 2. What does this print?
nums = [5, 2] nums.append(9) nums.append(1) print(len(nums)) print(nums[-1])
Question 3. What does this print?
marks = [60, 90, 75] marks.sort() print(marks[0], max(marks))
🧩 Your challenge
Make a shopping list helper. Ask for 4 items to buy from the market, store them in a list, then print each item with a number, like "1. tomatoes".
Item to buy: tomatoes Item to buy: onions Item to buy: rice Item to buy: curd 1. tomatoes 2. onions 3. rice 4. curd
⚠️ Common mistakes (and how to fix them)
❌ Wrong
days = ["Mon", "Tue", "Wed"] print(days[3])
IndexError: list index out of range
✅ Right
days = ["Mon", "Tue", "Wed"] print(days[2])
Three items have index 0, 1 and 2. There is no index 3, so Python stops with an error.
❌ Wrong
marks = [80, 70] marks.append(90, 60) print(marks)
TypeError: list.append() takes exactly one argument (2 given)
✅ Right
marks = [80, 70] marks.append(90) marks.append(60) print(marks)
append() adds exactly one item at a time. Call it once for each new item.
❌ Wrong
runs = [10, 20, 30]
total = 0
for r in runs:
total = r
print(total)No error message – but it prints 30, not the total 60.
✅ Right
runs = [10, 20, 30]
total = 0
for r in runs:
total = total + r
print(total)total = r throws away the old total each time. Add to it with total = total + r, or simply use sum(runs).
📌 Remember
- A list holds many values in order, inside square brackets [ ].
- Index numbers start at 0; list[-1] is the last item.
- append() adds one item to the end, and len() counts the items.
- for item in my_list: visits every item, one by one.
- in checks whether a value is in the list.
- sort() puts a list in order; sum(), max() and min() work on numbers.
Finished the quiz and the challenge?
Questions students ask
Why do Python lists start at index 0?
The index tells how far an item is from the start. The first item is 0 steps away, so its index is 0.
Can a Python list hold numbers and words together?
Yes, a list like ["Riya", 10, 92.5] is allowed. But sum(), max() and sort() work best when all items are the same type.
What is the difference between a list and a string?
A string holds letters of one piece of text. A list holds separate items, and you can change, add or sort them.
What happens if I use an index that does not exist?
Python stops with an IndexError. Use len() to know how many items there are; the last index is len minus 1.