What Are Lists?

STEP 1 β€” What Are Lists? (a.k.a. Your Game Backpack)

You’ve been working with single values so far:

weapon = "Sword"
potion = "Health Potion"
gold = 50

That works… until your player picks up five items, three keys, two potions, and a mysterious banana.

Suddenly, a bunch of separate variables feels like trying to carry loot with no backpack.

Enter Lists

A list is a way to store multiple values in a single variable.

inventory = ["Sword", "Health Potion", "Key", "Banana"]
print(inventory)

Now inventory is your backpack in code form.

  • Square brackets [] mean β€œthis is a list”
  • Items are separated by commas
  • Each item has a position (index) in the list
Click Run

Indexing: Python Starts at 0 (Because Of Course It Does)

inventory = ["Sword", "Health Potion", "Key", "Banana"]

print(inventory[0])   # Sword
print(inventory[1])   # Health Potion
print(inventory[2])   # Key
print(inventory[3])   # Banana

Python counts like:

  • 0 β†’ first item
  • 1 β†’ second item
  • 2 β†’ third item

It’s weird at first, then it becomes normal… like most of programming.

Click Run

Why Lists Matter for Games

Lists let you:

  • store all items in your inventory
  • keep track of enemies in a level
  • store dialogue lines
  • manage quests, levels, loot drops

Instead of writing:

enemy1 = "Goblin"
enemy2 = "Orc"
enemy3 = "Slime"

You can write:

enemies = ["Goblin", "Orc", "Slime"]
print(enemies)
Click Run

Much cleaner. Much more real developer.


Practice (Your Turn!)

Mini-Challenge

Create a list called weapons with three weapons in it.

Then print the first weapon and the third weapon.

Modify and Run

You just built your first weapon list.

Your game officially has a tiny armory.