Adding & Removing Items
(a.k.a. Looting, Yeeting, and Managing Your Game Inventory Like a Legend)
Your list is now a full-blown backpack.
But what good is a backpack if you canβt add new loot or yeet old junk out of it?
Welcome to the part where your inventory becomes ALIVE.
1. Adding Items (a.k.a. LOOT MODE ACTIVATED)
When your player finds something cool β a sword, a potion, or a suspiciously glowing potato β you add it to the list using .append().
inventory = ["Sword", "Potion"]
inventory.append("Shield")
print(inventory)
Output:
['Sword', 'Potion', 'Shield']
Boom.
Your player is now 12% more protected and 100% more stylish.
2. Removing Items (a.k.a. βGoodbye, Useless Junkβ)
Option A: Remove by name
inventory.remove("Potion")
Potion yeeted.
Hope you didnβt need it.
Option B: Remove by position
inventory.pop(0) # removes the first item
pop() is like reaching into your bag and pulling out a random snack. Except the snack disappears forever.
Option C: Pop the LAST item
inventory = ["Sword", "Potion", "Shield"]
last_item = inventory.pop()
print("You dropped:", last_item)
This is the βoops, butterfingersβ method.
3. Why This Matters for Games
Adding and removing items lets you build:
- inventory systems
- crafting systems
- shop menus
- loot drops
- enemy spawn lists
- quest item tracking
- equipment upgrades
Basically, everything that makes a game feel like a game.
Practice (Your Turn!)
Mini-Challenge #1
Start with this list:
inventory = ["Stick", "Rock"]
Add “Magic Wand” and “Potion”.
Then remove “Rock”.
Mini-Challenge #2
Create a list called loot.
Add three items to it.
Then use pop() to remove the last item and print:
You lost <item>!
Why did the list break up with the dictionary?
Because the dictionary kept defining the relationship.

