Python Dictionary update() Method
Description
The Python Dictionary update() function updates the key/value pairs of dictionary dict2 into dict.
Syntax
update() method syntax:
dict.update(dict2)
Parameters
- dict2 -- The dictionary to be added to the specified dictionary dict.
Return Value
This method does not return any value.
Examples
The following example demonstrates how to use the update() function:
Examples
#!/usr/bin/python
tinydict = {'Name': 'Zara', 'Age': 7}
tinydict2 = {'Sex': 'female' }
tinydict.update(tinydict2)
print ("Value : %s" % tinydict)
tinydict = {'Name': 'Zara', 'Age': 7}
tinydict2 = {'Sex': 'female' }
tinydict.update(tinydict2)
print ("Value : %s" % tinydict)
The output of the above example is:
Value : {'Age': 7, 'Name': 'Zara', 'Sex': 'female'}
Other Extensions
Python Dictionary