Dict
Dictionaries store key-value pairs and are the most commonly used mapping type in Python. This guide covers dictionary operations. The guide walks through Accessing Values, Iteration, Merging & Updating. `dict.get()` safely returns a default if key is missing. `dict.setdefault()` inserts and returns a default. Direct bracket access `d[key]` raises KeyError if missing. `dict[key] = value` sets values. `dict.keys()`, `dict.values()`, and `dict.items()` return view objects that reflect changes to the dict. Use `for k, v in d.items():` to iterate over key-value pairs. `dict.update()` merges another dict or iterable of pairs. The `|` operator (Python 3.9+) creates a new merged dict. `dict.pop()` removes and returns a value. The guide is organized into 3 sections that build on each other, each pairing a prose explanation with runnable code. Browse the individual functions covered by this guide in the Dictionary Methods category. Key APIs covered include dict.get(), dict.keys(), dict.values(), dict.items(), dict.update(), dict.pop().