A dictionary value may itself be a dictionary. Each pair of brackets selects the next level. The intermediate keys and values must exist and have the expected structure.
station = {
"name": "Hill",
"sensor": {"unit": "C", "reading": 18},
}
print(station["sensor"]["reading"])
station["sensor"]["reading"] = 19
print(station["sensor"])
18
{'unit': 'C', 'reading': 19}
The first lookup obtains the inner dictionary; the next lookup obtains or changes its reading. A missing key at either level raises KeyError. A shallow copy of station would still share that inner dictionary.
To merge mappings, decide which source wins when keys overlap. Here the later source wins:
morning = {"pear": 4, "plum": 2}
corrections = {"pear": 6, "fig": 3}
inventory = morning | corrections
print(inventory)
print(morning)
{'pear': 6, 'plum': 2, 'fig': 3}
{'pear': 4, 'plum': 2}
The | operator creates a new outer dictionary in Python 3.9 and later. The right-hand value replaces pear while plum remains and fig is added. The inputs stay unchanged; nested values, if present, remain shared. By contrast, morning.update(corrections) changes morning in place.