3.3.2 Common Dictionary Methods (keys / values / items)
Dictionaries provide built-in methods to inspect and access their contents.
keys()
The keys() method:
- Returns all keys in the dictionary
- Can be used for iteration or inspection
values()
The values() method:
- Returns all values stored in the dictionary
- Preserves the dictionary’s internal order
items()
The items() method:
- Returns key–value pairs
- Is commonly used when both keys and values are needed
📌 Note:
These methods return view objects that reflect changes in the dictionary.