PythonBit Logo

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!

Exercise 1 • python101-3-collections
No output yet...

1.1. 🍎 Quick Challenge: Fruit Basket Organizer!

  • Challenge:
  1. Follow the order to add "apple", "banana", "orange"
  2. Use .append() to add fruits one by one
  3. Use .extend() to add multiple fruits at once
  4. Print out your fruit basket
Exercise 2 • python101-3-collections
No output yet...

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.

Exercise 3 • python101-3-collections
No output yet...

2.1. 🗺️ Quick Tuple Challenge: Geocaching Coordinates!

  • Challenge: Create a tuple to represent a secret geocache location
  1. Make a tuple with 3 elements: (latitude, longitude, depth) => (37.7749, -122.4194, 10)
  2. Print out latitude
  3. Print out full location
Exercise 4 • python101-3-collections
No output yet...

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!

Exercise 5 • python101-3-collections
No output yet...

3.1. 🎮 Quick Challenge: Video Game Inventory System!

  • Challenge:
  1. Build an inventory with these 3 items
"health_potion": 5,
"magic_scroll": 3,
"golden_key": 1
  1. Add += 2 to the health potion quantity
  2. Update an item's quantity
  3. Print out your entire inventory
  4. Print Health Potions total quantity
Exercise 6 • python101-3-collections
No output yet...

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.

Exercise 7 • python101-3-collections
No output yet...

4.1. 🏆 Quick Challenge: Battle Royale Loadout!

  • Challenge:
  1. Create a set of weapons "assault rifle", "shotgun", "sniper", "grenades"
  2. Try to add a duplicate weapon
  3. Remove a weapon from your set "grenades"
  4. Check the total number of unique weapons
Exercise 8 • python101-3-collections
No output yet...

4.2. 🎮 Time for a Mini-Game: Collection Master!

Let's create a simple game inventory system using all our new powers!

Exercise 9 • python101-3-collections
No output yet...

4.3. 🎯 Debug Mission: Spot the Bugs!

Can you find and fix the problems in this code?

Exercise 10 • python101-3-collections
No output yet...

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! 🚀

Great job finishing the tutorial!

Ready to test your knowledge?

Take a quick quiz to reinforce what you've learned and make sure you've mastered the key concepts.