Merging two dictionaries using update()
We can merge two dictionaries by using the update() function.
Python3
veg_dict = { 0 : 'Carrot' , 1 : 'Raddish' , 2 : 'Brinjal' , 3 : 'Potato' } veg_dict.update({ 4 : 'Tomato' , 5 : 'Spinach' }) print (veg_dict) |
Output:
{0: ‘Carrot’, 1: ‘Raddish’, 2: ‘Brinjal’, 3: ‘Potato’, 4: ‘Tomato’, 5: ‘Spinach’}
How to add values to dictionary in Python
In this article, we will learn what are the different ways to add values in a dictionary in Python.
Contact Us