A dictionary key is the first item in a key–value pair: a hashable value used to locate its associated value. Keys may be integers, strings, or other hashable types, and each key is unique. section 5.0 section 5.20
Use keys to:
- Retrieve values with dictionary lookup or test whether a key exists using in. section 5.5
- Represent name–value data such as usernames, hostnames, configuration options, or product prices. section 5.0
- Iterate through dictionary keys or safely retrieve a possibly missing key with dict.get. section 5.20
Menu lookup
Store product names as keys and prices as values. After stripping input, check whether the order is a key before retrieving its price. Matching is case-sensitive; casefold can normalize user input before comparison. section 5.5
Keys must be hashable, while values may be any objects, including dictionaries. Square-bracket access ultimately invokes __getitem__; custom dictionary subclasses can reinterpret keys, but guessing between key types is discouraged. section 5.20 section 10.22









