Dictionaries
Table of contents
Description
A dictionary is a collection of key-value pairs enclosed by curly braces ({}). A colon (:) separates each key from its value.
- Mutable: you can change any of their attributes.
- Keys, like index numbers, allow access to individual values. Keys must be unique and immutable.
- Ordered: key/value pairs are stored in a dictionary in a specific order.
- Many different actions (methods and functions) can be performed on dictionaries.
- Python Docs: Dictionaries, Mapping Types
Example
Keys
- Keys must be an immutable data types. Dictionaries, lists, and sets cannot be dictionary keys because they are mutable.
- Keys must be unique. One dictionary cannot have two different keys by the same name.
Mutability
Dictionaries are mutable, which means their attributes can be changed after instantiation.