Dictionaries

A dictionary (dict) maps unique keys to values and allows fast access by key. It is written between curly braces, preserves insertion order and is iterated with .items(). The .get() method returns a default value rather than raising KeyError if the key is missing.

Example

user = {'nom': 'Léa', 'age': 30}
user.get('ville', 'inconnue')

Related concepts

The whole glossary