🪙 0
👋 📚 💻 🎯 🏆
🐍

Welcome to Python Adventure! 🎮

Hello there, young coder! I'm Pythonix, your friendly Python tutor!

Today we're going on an exciting adventure to learn about something super cool called SETS! 🎉

🎁 What you can earn today:

🪙 Coins
🏅 Badges
🥉🥈🥇 Trophies
1️⃣

What is a SET? 🤔

🎒 Imagine your school bag...

You have these items in your bag:

📚✏️📏🖍️📚

Wait! There are TWO books (📚)!

A SET is like a magic bag that keeps only ONE of each item! ✨

📚✏️📏🖍️

🔑 Key Points:

  • A SET is a collection of unique items
  • No duplicates allowed! 🚫
  • Items have no specific order

🎯 Quick Question!

If you put 🍎🍌🍎🍊🍌 into a SET, how many items will remain?

2️⃣

Let's Learn Sets! 📚

1/6

✨ Creating a Set

To create a set in Python, we use curly braces { }

Just like how you list your favorite things! 🌟

📝 Python Code:
fruits = {"apple", "banana", "orange"}
print(fruits)
Output: {'apple', 'banana', 'orange'}

🤔 Think & Answer:

Which one creates a set correctly?

2/6

🚫 No Duplicates Allowed!

Sets are super smart! They automatically remove duplicates! 🧠

If you try to add the same thing twice, the set says "Nope, already got it!"

📝 Python Code:
numbers = {1, 2, 2, 3, 3, 3}
print(numbers)
Output: {1, 2, 3}

🤔 Think & Answer:

What will this print? print({5, 5, 5, 5})

3/6

➕ Adding Elements

Want to add something new to your set? Use .add()! 🎁

It's like putting a new toy in your toy box!

📝 Python Code:
toys = {"ball", "car"}
toys.add("doll")
print(toys)
Output: {'ball', 'car', 'doll'}

🤔 Think & Answer:

How do you add "mango" to a set called fruits?

4/6

➖ Removing Elements

To remove something, use .remove() or .discard()! 🗑️

Tip: .discard() is safer - it won't give an error if item doesn't exist!

📝 Python Code:
colors = {"red", "blue", "green"}
colors.remove("blue")
print(colors)
Output: {'red', 'green'}

🤔 Think & Answer:

Which removes "cat" from a set called pets?

5/6

🔍 Checking if Item Exists

Want to check if something is in your set? Use in! 🕵️

It answers with True or False - like a yes/no question!

📝 Python Code:
snacks = {"chips", "cookies", "candy"}
print("chips" in snacks)
print("pizza" in snacks)
Output: True
False

🤔 Think & Answer:

If games = {"chess", "ludo"}, what is "chess" in games?

6/6

🔗 Set Operations (Union & Intersection)

Union (|) = Combine all items from both sets! 🤝

Intersection (&) = Find items that are in BOTH sets! 🎯

📝 Python Code:
set1 = {"a", "b", "c"}
set2 = {"b", "c", "d"}

print(set1 | set2)  # Union
print(set1 & set2)  # Intersection
Output: {'a', 'b', 'c', 'd'}
{'b', 'c'}

🤔 Think & Answer:

What does {1,2} & {2,3} give us?

3️⃣

Quiz Time! ❓

4️⃣

Coding Zone! 👨‍💻

5️⃣

Mini Challenge: Magic School Bag! 🎒

🧙‍♂️ You have a magical school bag! Complete these tasks:

  1. Create a set called bag with items: "book", "pencil", "eraser"
  2. Add "ruler" to the bag
  3. Remove "eraser" from the bag
  4. Print the final bag
📝 Your Code:
6️⃣

🏆 Your Results!

+5 🪙