Python Dictionary update

The Python Dictionary update is one of a Dictionary function 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 Python Dictionary update function. The syntax of this dictionary update function is:

dictionary_name.update(others)

Python Dictionary update Example

The Dictionary update function updates one dictionary with another dictionary.

TIP: Refer to the Dictionary in Python.

# Python Dictionary update Example

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

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