Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Dictionary update() method

Python Dictionary update() method

Python Dictionary Python Dictionary


Description

The Python Dictionary update() function updates dict with the key/value pairs from dictionary dict2.

Syntax

update() method syntax:



dict.update(dict2)

Parameters

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

)

print

(

"Value : %s"

%  tinydict

)

The output of the above example is:



Value : {'Age': 7, 'Name': 'Zara', 'Sex': 'female'}

Python Dictionary Python Dictionary