CHAPTER 7

The Backpack 🎒

Imagine you are going on a quest. You can't carry everything in your hands. You need a Backpack!

In Python, we call this a List (or Array). It holds many things in one variable.

📜 Lists & Indexing

We use square brackets [] to make a list.

backpack = ["Sword", "Shield", "Potion"]

Getting things out:

Computers start counting from Zero!

  • backpack[0] -> "Sword"
  • backpack[1] -> "Shield"
  • backpack[2] -> "Potion"

Adding things:

backpack.append("Map")

YOUR QUESTS ⚔️

Quest 1: Packing

Create a list called `food` with 3 items: "Pizza", "Apple", "Cake".

food = ["Pizza", "Apple", "Cake"]
Waiting for you to run code...

Quest 2: First Bite

Print the first item in your food list (Index 0!).

print(food[0])
Locked 🔒

Quest 3: More Food!

Use .append() to add "Ice Cream" to the list, then print the whole list.

food.append("Ice Cream")
print(food)
Locked 🔒

Wizard's Exam 📜

1. What is the index number of the FIRST item?

⌨️ EDITOR
Waiting for code...