The update() method updates the dictionary with the elements from the another dictionary object or from an iterable of key/value pairs.
Syntax:
dictionary.update(iterable)
Parameter:
This method takes either a dictionary or an iterable object of key/value pairs (generally tuples).
Return:
The method takes either a dictionary or an iterable object of key/value pairs (generally tuples).
Example:
dict_1 = {1:'a',2:'b'}
dict_2 = {3:'c',4:'d'}
dict_1.update(dict_2)
print(dict_1)
Output: {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
Tags