Python3 Dictionary update() Method
Description
The Python dictionary update() function adds the key/value pairs from dictionary parameter dict2 into dictionary dict.
Syntax
update() method syntax:
dict.update(dict2)
Parameters
- dict2 -- the dictionary to add to the specified dictionary dict.
Return Value
This method has no return value.
Example
The following example shows how to use the update() function:
Example (Python 2.0+)
#!/usr/bin/python3
tinydict
= {
'
Name
'
:
'
Runoob
'
,
'
Age
'
:
7
}
tinydict2
= {
'
Sex
'
:
'
female
'
}
tinydict
.
update
(
tinydict2
)
(
"
Update dictionary tinydict:
"
,
tinydict
)
The output of the above example is:
更新字典 tinydict : {'Name': 'Runoob', 'Age': 7, 'Sex': 'female'}
Python3 Dictionary