- As of Python 3.9, you can use the | symbol to merge them into a new dictionary.
dict3 = dict1 | dict2 - Or you can use |= to copy the right operand into the left operand.
dict1 |= dict2
The older alternative is to use the unpack operator (**) which works (like the spread operator in JavaScript. Unpack of the dictionaries into a new dictionary, as shown below.
dict1 = {"a": 1, "b": 2}
dict2 = {"c": 3, "d": 4}
merged_dict = {**dict1, **dict2}