In this tutorial, we will learn about how to concatenate two dictionaries into one dictionary.
Explanation ✏
First, we need to create two dictionaries
Then, with the help of the update() function we can add a second to the first dictionary.
Finally, print the output
Code 👩💻
dict1 = {'a':5,'b':10,'c':15}
dict2 = {'d':20,'e':25,'f':30}
dict1.update(dict2)
print(dict1)
Output : {'a':5, 'b':10, 'c':15, 'd':20, 'e':25, 'f':30}
Another Method:- Another way to merge two Python dictionaries using (**)
Code 👩💻
dict1 = {'a':5,'b':10,'c':15}
dict2 = {'d':20,'e':25,'f':30}
print({**dict1, **dict2})