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

Python3 Dictionary update() Method

Python3 Dictionary update() Method

Python3 Dictionaries Python3 Dictionary


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

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

)

print

(

"

Update dictionary tinydict:

"

,

tinydict

)

The output of the above example is:


更新字典 tinydict :  {'Name': 'Runoob', 'Age': 7, 'Sex': 'female'}

Python3 Dictionaries Python3 Dictionary