1. Home
  2. Data Science
  3. Python
  4. What is the output of the following Python code snippet?

Added 25 Nov 2026

What is the output of the following Python code snippet?

d = {'a': 1}
print(d.get('z'))
  1. KeyError
  2. None Correct answer
  3. 0
  4. Error

Correct answer

B. None

6 views

MCQSEXAM

Explanation

get() returns None instead of raising KeyError when the key is missing.

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 B? 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