If a dictionary is updated with an empty key/value will it erase the contents of the dictionary?


#1

Question

If the dictionary update() is called with no parameters OR an empty dictionary, will the update erase the existing contents of the dictionary?

Answer

NO, calling update() with no parameters or with an empty dictionary will not change any of the existing key/values in the dictionary. The following code example shows both types of empty updates. The existing dictionary remains unchanged.

cities = dict()

cities.update({"San Francisco": 75, "Chicago": 100})
cities.update()
cities.update({})

print(cities)
# {'San Francisco': 75, 'Chicago': 100}