computer4kids is now ComputerLeap. Same free lessons, same team. Read why we changed our name

← All lessons · 🧑‍💻 Coding Academy

📋

🎓

⏱ 25 min

Free

Lists: Collections of Things

Store many values in one variable, grab items by position and change your list.

🎯 What you will learn

  • Create lists with [ ]
  • Access items by index (starting at 0)
  • Add, remove and count items

👋 Let’s get started!

What if a game has 100 players? 100 variables? No way! A LIST stores many values in one place, in order. 📋

🪜 Step by step

1. 📋 Make a list

Put items in square brackets, separated by commas.

snacks = ["apple", "popcorn", "grapes"]
print(snacks)
2. 🔢 Index from 0

Each item has a position called an index. The first one is 0!

print(snacks[0])   # apple
print(snacks[-1])  # last item
3. ✏️ Change it

append() adds, remove() deletes, len() counts.

snacks.append("cheese")
snacks.remove("popcorn")
print(len(snacks))

🧪 Try it!

Change the code and press ▶ Run to see what happens. You can’t break anything!

Backpack inventory

backpack = ["map", "flashlight"]
backpack.append("snacks 🍪")
backpack.append("compass 🧭")
print("I have", len(backpack), "items:")
for item in backpack:
    print("-", item)

Build a playlist

songs = []
songs.append("Happy")
songs.append("Believer")
print(songs[1])

📖 Key words

Tap a card to flip it over!

List
An ordered collection [ ] 📋
Index
Position in a list, starting at 0 🔢
append()
Adds to the end of a list ➕
len()
Counts items 📏

🏆 Challenge

Print the third planet from this list.

Challenge

planets = ["Mercury", "Venus", "Earth", "Mars"]

Knowledge Check Quiz

  1. What prints?
  2. What does append() do?
  3. What prints?
← Previous lesson
Next lesson →