3. Python Collections
Learn about Python's amazing ways to store and organize data
Level Up with Python's Super Storage Powers! 🦸♂️
Hey coding champions! Ready to learn about Python's amazing ways to store and organize stuff? It's like having different types of super-powered containers for your data! 🎮
1. Lists: Your Digital Backpack 🎒
Imagine you're packing for an epic adventure. A list in Python is like your backpack - you can put anything in it, take stuff out, add more things, and even change what's inside!
1.1. 🍎 Quick Challenge: Fruit Basket Organizer!
- Challenge:
- Follow the order to add "apple", "banana", "orange"
- Use .append() to add fruits one by one
- Use .extend() to add multiple fruits at once
- Print out your fruit basket
2. Tuples: The Unbreakable Container 🔒
Think of tuples like your favorite LEGO set - once it's built, you can't change the pieces! They're perfect for things that shouldn't change, like the days of the week or your birthday.
2.1. 🗺️ Quick Tuple Challenge: Geocaching Coordinates!
- Challenge: Create a tuple to represent a secret geocache location
- Make a tuple with 3 elements: (latitude, longitude, depth) => (37.7749, -122.4194, 10)
- Print out latitude
- Print out full location
3. Dictionaries: Your Personal Game Guide 🗺️
Dictionaries are like your game cheat sheet - each item (key) has its own special information (value). It's perfect for storing character stats or game settings!
3.1. 🎮 Quick Challenge: Video Game Inventory System!
- Challenge:
- Build an inventory with these 3 items
"health_potion": 5,
"magic_scroll": 3,
"golden_key": 1
- Add += 2 to the health potion quantity
- Update an item's quantity
- Print out your entire inventory
- Print Health Potions total quantity
4. Sets: Your Sticker Collection 🌟
Sets are like your sticker collection - you can't have duplicates! If you try to add the same sticker twice, it only keeps one copy.
4.1. 🏆 Quick Challenge: Battle Royale Loadout!
- Challenge:
- Create a set of weapons
"assault rifle", "shotgun", "sniper", "grenades"
- Try to add a duplicate weapon
- Remove a weapon from your set
"grenades"
- Check the total number of unique weapons
4.2. 🎮 Time for a Mini-Game: Collection Master!
Let's create a simple game inventory system using all our new powers!
4.3. 🎯 Debug Mission: Spot the Bugs!
Can you find and fix the problems in this code?
5. 🌈 Remember:
- Lists are like your backpack (can change anytime)
- Tuples are like LEGO sets (can't change after building)
- Dictionaries are like game guides (each thing has its info)
- Sets are like sticker collections (no duplicates allowed!)
Ready to become a Python Collection Master? Let's code! 💪 Need a hint? Just ask! We're in this adventure together! 🚀