1. Home
  2. Data Science
  3. Python
  4. With counts = defaultdict(int), what does counts['new']…

Added 2 Nov 2026

With counts = defaultdict(int), what does counts['new'] return for a key never set before?

  1. None
  2. KeyError
  3. 0 Correct answer
  4. ''

Correct answer

C. 0

18 views

MCQSEXAM

Explanation

defaultdict(int) calls int() to create a default of 0 for missing keys, which makes counting idioms such as counts[word] += 1 work without checks.

Reference

Asked in: NTS, Python Developer Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs