Skip to main content

Python: Update Dictionary

The update() method updates the dictionary with the elements from the another dictionary object or from an iterable of key/value pairs.

Syntax:

dictionary.update(iterable)

Parameter:

This method takes either a dictionary or an iterable object of key/value pairs (generally tuples).

Return:

The method takes either a dictionary or an iterable object of key/value pairs (generally tuples).

Example:

dict_1 = {1:'a',2:'b'}
dict_2 = {3:'c',4:'d'}
dict_1.update(dict_2)
print(dict_1)

Output: {1: 'a', 2: 'b', 3: 'c', 4: 'd'}

Tags
Submitted by devanshi.srivastava on June 25, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.