Python Sets: Unordered, Mutable, No Duplicates

🚀 Day 12 – Python Sets (Multiple Valued Data Type) Today I explored Sets in Python — one of the powerful multiple valued data types! 🔷 🔹 What is a Set? A Set is a collection of multiple items that is: ✅ Unordered ❌ No indexing ✅ Mutable ❌ No duplicate values 📌 Sets are written using curly brackets {} my_set = {10, 20, 30, 40} print(my_set) 🔷 🔹 Important Characteristics 👉 Duplicates are automatically removed numbers = {1, 2, 2, 3, 4} print(numbers) # Output: {1, 2, 3, 4} 👉 Cannot access using index my_set[0] # ❌ Error 👉 We can add or remove elements fruits = {"apple", "banana"} fruits.add("mango") fruits.remove("banana") 🔷 🔹 Set Operations (Mathematical Power 💪) A = {1, 2, 3} B = {3, 4, 5} ✔️ Union → Combines both sets A.union(B) ✔️ Intersection → Common elements A.intersection(B) ✔️ Difference → Unique elements A.difference(B) 🔷 🔹 When Should We Use Sets? ✨ Removing duplicate data ✨ Performing mathematical operations ✨ Faster searching (membership testing) 🌟 Day 12 Complete! Learning step by step, building strong Python fundamentals. #Python #Day12 #LearningPython #DataTypes #Sets #ProgrammingJourney 💻

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories