🐸

The Backpack

Python Basicspython-basics-23-the-backpack
Reward: 110 XP
|

The Magic Backpack

Hoppy found a magical backpack! It can hold many items in a specific order.

In Python, this is called a List. Lists are created using square brackets [].

Creating a List

# A list of numbers
numbers = [1, 2, 3, 4, 5]

# A list of strings (items)
backpack = ["Sword", "Shield", "Potion"]

# An empty list
empty_bag = []

Your Mission

1
Prepare the Bag

Create a variable named inventory.

2
Pack Items

Assign a list to it containing three strings: "Map", "Compass", and "Snack".

3
Check

Print the inventory.

Suggested Solution
Click to expand

Here is how you pack your bag:

inventory = ["Map", "Compass", "Snack"]
print(inventory)
Advanced Tips
Want more? Click to expand

Lists can hold different types of data at the same time!

mixed_bag = ["Sword", 10, True, 3.14]
pymain.py
Loading...
Terminal
Terminal
Ready to run...