Python3 Dictionary update() Method
Description
The Python dictionary update() function takes the dictionary parameter dict2'skey/valuepairs and updates them into the dictionary dict.
Syntax
The syntax of the update() method is:
dict.update(dict2)
Parameters
- dict2 -- The dictionary to be added to the specified dictionary dict.
Return Value
This method does not return any value.
Example
The following example demonstrates how to use the update() function:
Example (Python 2.0+)
#!/usr/bin/python3
tinydict = {'Name': 'Example', 'Age': 7}
tinydict2 = {'Sex': 'female' }
tinydict.update(tinydict2)
print ("Update the dictionary tinydict:", tinydict)
The output of the above example is:
更新字典 tinydict : {'Name': 'Example', 'Age': 7, 'Sex': 'female'}
Other Extensions
Python3 Dictionary