Python Dictionary update() method
Description
The Python Dictionary update() function updates dict with the key/value pairs from dictionary dict2.
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
#!/usr/bin/python
tinydict
=
{
'Name'
:
'Zara'
,
'Age'
:
7
}
tinydict2
=
{
'Sex'
:
'female'
}
tinydict.
update
(
tinydict2
)
(
"Value : %s"
% tinydict
)
The output of the above example is:
Value : {'Age': 7, 'Name': 'Zara', 'Sex': 'female'}
Python Dictionary