Python dictionary update() method
Python Dictionary update() Method
Description
The Python dictionary method update() adds the key-value pairs of the dictionary dict2 to dict. This function does not return any value.
Syntax
The following is the syntax of the update() method –
dict.update(dict2)
Parameters
- dict2 – The dictionary to be added to dict.
Return Value
This method does not return any value.
Example
The following example demonstrates the use of the update() method.
dict = {'Name': 'Zara', 'Age': 7}
dict2 = {'Sex': 'female' }
dict.update(dict2)
print "Value : %s" % dict
When we run the above program, the following output is produced −
Value : {'Age': 7, 'Name': 'Zara', 'Sex': 'female'}