Python dictionary update() Method
Advertisements
Description
The method update() adds dictionary dict2's key-values pairs in to dict. This function does not return anything.
Syntax
Following is the syntax for update() method
dict.update(dict2)
Parameters
dict2 -- This is the dictionary to be added into dict.
Return Value
This method does not return any value.
Example
The following example shows the usage of update() method.
#!/usr/bin/python
dict = {'Name': 'Zara', 'Age': 7}
dict2 = {'Sex': 'female' }
dict.update(dict2)
print "Value : %s" % dict
Let us compile and run the above program, this will produce the following result:
Value : {'Age': 7, 'Name': 'Zara', 'Sex': 'female'}