Latest web development tutorials

Python dictionary (Dictionary) update () method

description

Python dictionary (Dictionary) update () function to the dictionary dict2 key / value pairs in the update to the dict.

grammar

update () method syntax:

dict.update(dict2)

parameter

  • dict2 - added to the dictionary dict specified in the dictionary.

return value

This method has no return value.

Examples

The following example shows the update () method using the function:

#!/usr/bin/python

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

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

The above example output is:

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