Name

.update()

Examples

element_names = {'H': 'hydrogen', 'He': 'helium', 'Li': 'lithium'}
additional_elements = {'B': 'boron', 'C': 'carbon', 'N': 'nitrogen'}

print(len(element_names)) # Prints 3

# "Update" original dictionary with new values
element_names.update(additional_elements)

print(len(element_names)) # Prints 6
print(element_names['N']) # Prints "Nitrogen"

# Updating with an existing key will overwrite the value for that key!
wrong_elements_oh_no = {'H': 'Happiness'}
element_names.update(wrong_elements_oh_no)

print(element_names['H']) # Prints "Happiness"

Description "Updates" a dictionary with the contents of a second dictionary. Any key/value pairs present in the second dictionary will be added to the first. If the second dictionary contains a key present in the first dictionary, its value will be overwritten with the value from the second dictionary.
Syntax
	dict1.update(dict2)
Parameters
dict1The dictionary to be updated.
dict2The source dictionary for the update, where new key/value pairs will be drawn from.
Related Dictionary

Updated on Mon Sep 21 15:53:24 2020.

If you see any errors or have comments, please let us know.