Python dictionary update() Method


Advertisements


Description

The method update() adds dictionary dict2's key-values pairs in to dict. This function does not return anything.

Syntax

Following is the syntax for update() method −

dict.update(dict2)

Parameters

  • dict2 − This is the dictionary to be added into dict.

Return Value

This method does not return any value.

Example

The following example shows the usage of update() method.

Live Demo
#!/usr/bin/python

dict = {'Name': 'Zara', 'Age': 7}
dict2 = {'Sex': 'female' }

dict.update(dict2)
print "Value : %s" %  dict

When we run above program, it produces following result −

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

python_dictionary.htm

Advertisements