The merge operator is a new feature in Python 3.9 that allows you to “merge two dictionaries”. The syntax of the merge operator is a “pipe character (|)”.
Syntax
dict1 | dict2
Operands
- dict1: Current dictionary object
- dict2: Another dictionary object
Return value
It returns the merged dictionary as a dict instance. The “merge operator” creates a new dictionary containing both dictionaries’ keys and values. If there are duplicate keys, the value from the right-hand dictionary will be used.
Example: How to Use Merge Operator in Python
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
new_dict = dict1 | dict2
print(new_dict)
Output
{'a': 1, 'b': 2, 'c': 3, 'd': 4}
The “merge operator” is a convenient way to merge two dictionaries. It is shorter, more concise than the “dictionary.update()” method, and more readable.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.