1. Home
  2. Data Science
  3. Python
  4. What error is raised when accessing a missing dict key…

Added 25 Nov 2026

What error is raised when accessing a missing dict key with d[key] in Python?

  1. IndexError
  2. ValueError
  3. KeyError Correct answer
  4. NameError

Correct answer

C. KeyError

5 views

MCQSEXAM

Explanation

Looking up a missing key with square brackets raises KeyError.

Reference

Asked in: Python Interview Dictionaries

https://docs.python.org/3/tutorial/datastructures.html#dictionaries

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