To append a dictionary to another dictionary in Python, you can use the update()
method or dictionary unpacking.
Using update()
:
Output: {'a': 1, 'b': 2, 'c': 3, 'd': 4}
Using Dictionary Unpacking (Python 3.5+):
Output: {'a': 1, 'b': 2, 'c': 3, 'd': 4}
Both approaches add the key-value pairs from dict2
to dict1
.