dictionary {}
Stores key-value pairs.
Syntax
name = {"key": value}Description
A dictionary is created with curly braces. A value is accessed via its key (not an index). It's like 'labeled boxes' in the real world.
Returns
A dictionary object.
Example
Loading editor…
Expected output
Alex
{'name': 'Alex', 'age': 36, 'city': 'London'}When to use?
Holding an object's attributes (a user, a product); JSON data.
Common mistakes
- ⚠️ Accessing a missing key raises an error; use .get() for safe access.