dict.keys() vs dict.values()
dict.keys() and dict.values() are both Python Dictionary Methods APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. dict.keys(): Returns a view object of all keys in the dictionary. Its syntax is dict.keys(), and it returns keys view dict.values(): Returns a view object of all values in the dictionary. Its syntax is dict.values(), and it returns values view Example of dict.keys(): d = {"a": 1, "b": 2}
list(d.keys()) # ["a", "b"]. Example of dict.values(): d = {"a": 1, "b": 2}
list(d.values()) # [1, 2]. Read the full references for dict.keys() and dict.values() to see parameters, edge cases, and example code side by side. Other Dictionary Methods APIs worth comparing: dict.get(), dict.items(), dict.update(), dict.pop(), dict.popitem(), dict.setdefault(). Both belong to the Dictionary Methods category in the Python Reference documentation.