Skip to content

Commit 473f3ee

Browse files
authored
Merge pull request #72 from braboj/codex/add-title-and-explanation-to-operators_dict.py
Add explanation for dictionary merge operators
2 parents 1b6628c + bff978b commit 473f3ee

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

examples/04_operators/operators_dict.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Merging and updating dictionaries
2+
# -----------------------------------------------------------------------------
3+
# Python 3.9 introduced the | and |= operators to combine dictionaries. The |
4+
# operator creates a new dictionary containing keys from both operands, while
5+
# |= updates the dictionary on the left in place. This provides a concise
6+
# alternative to using the update() method or ** unpacking for merging.
7+
18
a = {'a': 1, 'b': 2, 'c': 3}
29
b = {'d': 4, 'e': 5}
310

0 commit comments

Comments
 (0)