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 SolutionClick to expandClick to collapse
Here is how you pack your bag:
inventory = ["Map", "Compass", "Snack"] print(inventory)
Advanced TipsWant more? Click to expandClick to collapse
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...