Python dictionary update() Method


Contents

Description

Python dictionary method update() inserts dictionary dict2's key-values couples in to dict. This meaning never return anything. The update() process updates the lexicon with the parts from an additional dictionary article or from an iterable of key/value pairs. The update() method affixes element(s) to the dictionary if the input is not in the dictionary. If the key is in the glossary, it updates the key with the fresh value.

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.

#!/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'}

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.



Navigation
Tutorial
Tutorial
Tutorial