← Back to Python Course Foundations
Collections (Tuple, Set, Dictionary)¶
Learning Objectives¶
- Use tuple for fixed data.
- Use set for unique values and set operations.
- Use dictionary for key-value storage.
Example¶
t = (10, 20, 10)
print(t.count(10), t.index(20))
s = {1, 2, 2, 3}
s.add(4)
print(s)
d = {"name": "Ravi", "marks": 88}
print(d.get("name"))
d["grade"] = "A"
print(d)
Dry Run¶
- Tuple keeps duplicates and order.
- Set removes duplicates automatically.
- Dictionary accesses values by key.
Practice¶
- Build attendance set for unique roll numbers.
- Store student details in dictionary and update marks.