What is the output of the following Python code snippet?
d = {'a': 1, 'b': 2}
d.update({'b': 3, 'c': 4})
print(d)
d.update({'b': 3, 'c': 4})
print(d)
Correct answer
D. {'a': 1, 'b': 3, 'c': 4}
6 views
D. {'a': 1, 'b': 3, 'c': 4}
6 views
update() adds new keys and overwrites existing ones.
Asked in: Python Interview Dictionaries
https://docs.python.org/3/tutorial/datastructures.html#dictionariesNot sure why the answer is D? Ask here and get an explanation.