Lesson 06 � Foundation

TUPLES & SETS:
FIXED AUR UNIQUE DATA

Kabhi kabhi data change nahi hona chahiye � jaise coordinates ya RGB values. Tuple woh collection hai jo ek baar banne ke baad fix rehta hai. Aur Set✓ Woh sirf unique values rakhta hai, duplicates ko kaat deta hai.

? 18 min BeginnerPrerequisite: Lists

WHY: tuples aur sets kyun zaruri hain

Tuples unmutable collections hain jab data change nahi hona chahiye (coordinates, RGB values, function returns). Sets unique values store karte hain aur mathematical set operations support karte hain.

FIXED

Tuple ek baar banne ke baad change nahi hota.

UNIQUE

Set sirf unique values rakhta hai.

ORDERED

Tuple ordered hai, Set unordered.

WHAT: tuples aur sets basic syntax

python
# Tuples
colors = ("red", "green", "blue")
print(colors[0]) # red
print(len(colors)) # 3

# Tuple unpacking
x, y, z = colors
print(x) # red

# Sets
unique_numbers = {1, 2, 3, 2, 1}
print(unique_numbers) # {1, 2, 3}

# Set operations
a = {1, 2, 3}
b = {3, 4, 5}
print(a | b) # union: {1, 2, 3, 4, 5}
print(a & b) # intersection: {3}

WHEN: tuples aur sets kab use karein

Tuples tab use karo jab data fixed hona chahiye (coordinates, database rows). Sets tab jab duplicates remove karne ho ya set operations (union, intersection) karo.

Try it: tuples & sets playgroundCoordinates aur unique students ke saath practice karo
Run Python dabayein

Useful tuple & set operations

Quick check

Ek tuple banao jisme 3 cities ho: Lucknow, Delhi, Mumbai. Answer mein tuple use karo.

Tuple parentheses mein hota hai aur values comma-separated hote hain.

Common mistakes

Tuples & Sets clear?

Ab key-value pairs ke saath Dictionaries dekhte hain.