keys() / values() / items()
Iterates over the keys, values or pairs.
Syntax
dict.keys() · .values() · .items()
Description
keys() gives all keys, values() gives all values. items() gives (key, value) pairs — very commonly used in loops.
Example
Loading editor…
Expected output
a 1 b 2
When to use?
Processing all of a dictionary's contents with a loop.