SoFunction
Updated on 2024-11-21

Using the update method to manipulate dictionaries in Python.

The update() method adds a key-value pair to the dictionary dict2. This function does not return any value.
vocabulary

The following is the syntax of the update() method:

(dict2)

parameters

  • dict2 -- This is the dictionary to which the dict was added.

return value

This method does not return any value
(for) instance

The following example shows the use of the update() method

#!/usr/bin/python

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

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

When we run the above program, it produces the following results:

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