Python Dictionary update

The Python Dictionary update method is used to update key-value pairs of a dictionary. It is instrumental in updating one dictionary values with other or in inserting key-value pairs from user inputs.

In this section, we discuss how to use this function. The syntax of this dictionary update function is:

dictionary_name.update(others)

Python Dictionary update Example

The update method updates the dictionary object with another dictionary.

TIP: Refer to the Dictionary in Python.

myDict = {1: 'apple', 2: 'Banana'}
myNewDict = {3: 'Orange', 4: 'Kiwi'}
print("Dictionary Items: ", myDict)
print("New Dictionary Items: ", myNewDict)

myDict.update(myNewDict)
print("\nDictionary Items  :  ",  myDict)
Python Dictionary update Example