🎯 What you will learn
- A list holds many items in order
- len() counts items
- append() adds a new item
👋 Let’s get started!
Your Minecraft backpack holds lots of items in a row. In code, that row is a list. Lists can grow, shrink and be counted. 🎒
🪜 Step by step
1. 🎒 A list
A list keeps items in square brackets, separated by commas.
bag = ["wood", "stone", "torch"]
print(bag)
2. 🔢 Count
len() tells you how many items are in the list.
print(len(bag))
3. ➕ Add
append() adds one item to the end of the list.
bag.append("apple")
print(bag)
🧪 Try it!
Change the code and press ▶ Run to see what happens. You can’t break anything!
Check the backpack
bag = ["wood", "stone", "torch"]
bag.append("apple")
print("Items:", len(bag))
for item in bag:
print("I have", item)🎨 Unplugged activity
🎒 Make a real backpack list on paper with 5 items. Add 2 more and count them out loud, like len() does.
Pack your bag
bag = []
bag.append("sword")
bag.append("bread")
print(len(bag))📖 Key words
Tap a card to flip it over!
- List
- Many items in order 🎒
- append()
- Adds to the end ➕
- len()
- Counts the items 🔢
🏆 Challenge
Start with bag = [“wood”]. Add “stone” and print how many items the bag has now. Press ▶ Run.
Challenge
bag = ["wood"]
Knowledge Check Quiz
- What does append() do?
- What does len(bag) give?
- Which is a list?