🐍 Python for kids · Class 6 · Lesson 10 of 18 · Free
Introduction to Lists – Index, Slice, Add and Remove
⏱ About 30 minutes · ▶ run real Python here — nothing to install · no sign-in
In this lesson you will
- Create a list and read any item with a positive or negative index.
- Cut out part of a list with a slice like marks[1:4].
- Change a list with append(), insert(), remove() and pop().
Your class has 40 students. Would you make 40 variables called student1, student2 and so on? No way! A list keeps all 40 names in one variable, in order.
What is a list in Python?
A list is one variable that holds many values in order. You write it with square brackets and commas.
A list can hold numbers, text, or even a mix. Most lists hold one kind of thing, like all marks or all names.
len() tells you how many items are in the list. An empty list [] has length 0.
['Ananya', 'Kabir', 'Diya', 'Rohan'] Number of toppers: 4 Empty list length: 0
How does list indexing work in Python?
Each item has a position number called an index. Python starts counting at 0, not 1.
So the first item is list[0] and the second is list[1]. The last index is always len(list) - 1.
Negative indexes count from the end. list[-1] is the last item and list[-2] is the second last.
▶planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter"]2print("First:", planets[0])3print("Third:", planets[2])4print("Last:", planets[-1])5print("Second last:", planets[-2])6last_index = len(planets) - 17print("Last index is", last_index)
No variables yet.
▌✏️ Change this code and run it yourself
First: Mercury Third: Earth Last: Jupiter Second last: Mars Last index is 4
💡 Think of a lift: the ground floor is 0. Python numbers list items the same way.
How do I change an item in a list?
Lists are mutable. That means you can change them after you create them.
Put the index on the left of = to replace an item. The other items stay where they are.
Negative indexes work here too. timetable[-1] = "PT" changes the last period.
This is different from a string. You cannot change one letter of a string in place, but you can change a list item.
Before: ['Maths', 'English', 'Science', 'Hindi'] After: ['Maths', 'English', 'Computers', 'PT']
How do I add items with append() and insert()?
append() adds one item to the end of the list. The list grows by one.
insert() puts an item at a chosen index. Everything after it moves one place to the right.
Here a playlist starts with two songs. We add one at the end and push one to the very front.
Watch the trace. After insert(0, ...), every old song gets a new index one bigger than before.
▶playlist = ["Song A", "Song B"]2playlist.append("Song C")3print(playlist)4playlist.insert(0, "Jana Gana Mana")5print(playlist)6new_song = input("Add a song: ")7playlist.append(new_song)8print(playlist, "has", len(playlist), "songs")
No variables yet.
▌✏️ Change this code and run it yourself
['Song A', 'Song B', 'Song C'] ['Jana Gana Mana', 'Song A', 'Song B', 'Song C'] Add a song: Vande Mataram ['Jana Gana Mana', 'Song A', 'Song B', 'Song C', 'Vande Mataram'] has 5 songs
How do I remove items with remove() and pop()?
remove(value) deletes the first item that matches the value. You say what to remove.
pop(index) deletes the item at that index and gives it back to you. pop() with no index takes the last item.
Use in first to check that a value exists. remove() crashes if the value is not in the list.
After remove: ['pen', 'eraser', 'pencil', 'sharpener'] Popped sharpener -> ['pen', 'eraser', 'pencil'] Popped pen -> ['eraser', 'pencil'] No glue in the bag.
💡 pop() is useful when you need the item you took out, like the next person in a queue.
How do I get part of a list with slicing?
A slice copies a piece of a list. You write list[start:stop], just like range().
The slice starts at start and stops before stop. Leave out start to begin at 0, or stop to go to the end.
Slicing never changes the original list. It makes a new, smaller list.
runs[-2:] is a neat trick. It means "start two from the end and go to the end".
First three: [12, 45, 7] Middle: [7, 88, 30] From index 4: [30, 61, 4] Last two: [61, 4] Original: [12, 45, 7, 88, 30, 61, 4]
🤔 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", "yellow"] print(colours[1], colours[-1])
Question 2. What does this print?
nums = [5, 10, 15] nums.append(20) nums.insert(1, 7) print(nums)
Question 3. What does this print?
letters = ["a", "b", "c", "d", "e"] print(letters[1:3], len(letters))
🧩 Your challenge
Manage a canteen queue. Start with the list ["Riya", "Om", "Sana"]. Ask for a new student's name and add them to the end. Then serve the first person with pop(0) and print who was served. Finally print the queue and how many are still waiting.
Who joins the queue? Vikram Served: Riya Queue now: ['Om', 'Sana', 'Vikram'] Still waiting: 3
⚠️ 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])
A list of 3 items has indexes 0, 1 and 2. Index 3 does not exist.
❌ Wrong
fruits = ["mango", "apple"]
fruits.remove("banana")ValueError: list.remove(x): x not in list
✅ Right
fruits = ["mango", "apple"]
if "banana" in fruits:
fruits.remove("banana")
print(fruits)remove() needs the value to be in the list. Check with in before you remove.
❌ Wrong
scores = [10, 20] scores = scores.append(30) print(scores)
No error message – but it prints None, and the list is lost.
✅ Right
scores = [10, 20] scores.append(30) print(scores)
append() changes the list itself and gives back None. Do not store its result in the list variable.
📌 Remember
- A list stores many values in order inside square brackets.
- Indexes start at 0; -1 means the last item.
- list[i] = value replaces an item, because lists are mutable.
- append() adds to the end; insert(i, x) adds at a position.
- remove(x) deletes by value; pop(i) deletes by index and returns the item.
- list[a:b] makes a new list from index a up to, but not including, b.
Finished the quiz and the challenge?
Questions students ask
Why do Python lists start at index 0?
The index tells Python how many steps to move from the start. The first item is zero steps away, so it is index 0.
What is the difference between remove() and pop() in Python?
remove() deletes an item by its value. pop() deletes an item by its index and also returns it to you.
What does IndexError: list index out of range mean?
You asked for a position that does not exist. Check len(list); the last index is one less than the length.
Can a Python list hold different types?
Yes, like ["Asha", 12, 4.5]. But it is usually clearer to keep one kind of thing in each list.