What is the output of the following Python code snippet?
d = {'a': 1}
print(d.get('z'))
print(d.get('z'))
Correct answer
B. None
6 views
B. None
6 views
get() returns None instead of raising KeyError when the key is missing.
Asked in: Python Interview Dictionaries
https://docs.python.org/3/tutorial/datastructures.html#dictionariesNot sure why the answer is B? Ask here and get an explanation.