Python Dictionary Key Types
Multiple Choice Medium
Question
Which of the following can be used as a Python dictionary key?
Hint
Keys must be hashable (immutable).
Explanation
Dictionary keys must be hashable. Tuples are immutable and hashable, so (1, 2) works. Lists, dicts, and sets are mutable and unhashable, so they cannot be keys. Strings, numbers, and frozensets also work as keys.
Related Resources
Related Lessons
- Dictionaries
Dictionary keys.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.