dict.setdefault()
dict.setdefault() works on a dictionary — labelled data like marks["Asha"] = 90. Keys map to values. Loop with .items() when you need both.
dict.setdefault() — output — 90, then 0, then {'Asha': 90, 'Neha': 0}. setdefault adds only if missing.
Trap for dict.setdefault() — writing d[missing] in a viva. Prefer get when the key might not exist.
{ "Asha": 90, "Ravi": 85 }
│ │
key valueExam tip
get vs [] — one sentence + tiny dict of marks.