Python TutorialLesson 17Free preview
Python Dictionaries
This lesson is part of Python · All levels
Summary
The dictionary stores data in the form of key pairs and values so that the values can be taken based on the key, not the order. We access the value with d[key] or use d.get(key, default) to avoid errors when the key is not found. Dictionaries are very commonly used for structured data such as user data, configuration, or mapping results.
Key points
- The dictionary is written in curly braces containing the key pair: value.
- The key must be unique and hashable, such as a string or a number.
- Access to an unknown key by [] creates a KeyError.
- Method get() returns the default when the key is not present.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.