Python Learning Series · @onlysamarrr · Day 19 / 30
Day 19 teaches sets. A set holds only unique values: duplicates are removed automatically. Union (|), intersection (&), difference (-) and symmetric difference (^) compare sets.
Phase: Intermediate · Reels: 91/450 – 95/450
Day 19 teaches sets. A set holds only unique values: duplicates are removed automatically. Union (|), intersection (&), difference (-) and symmetric difference (^) compare sets.
a = {1, 2, 3}
b = {2, 3, 4}
print(a | b)
print(a & b)
print(a - b)
print(a ^ b)
visits = ["u1", "u2", "u1", "u3"]
print(len(set(visits)))
print(set())
{1, 2, 3, 4}
{2, 3}
{1}
{1, 4}
3
set()
Unique visitors, common friends and duplicate removal all use sets.
Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.
Q1. What is {1, 2} | {2, 3}?
Q2. What is {1, 2} & {2, 3}?
Q3. What is {} in Python?
| 91/450 | Concept | Set kya hai |
| 92/450 | Live demo | Union, intersection demo |
| 93/450 | Common mistake | {} empty set nahi hai |
| 94/450 | Quiz | Quiz: common elements |
| 95/450 | Interview / real life | Real life: unique visitors |