GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Python Dictionary keys() method - GeeksforGeeks Python Dictionary keys() methodLast Updated : 3 Jun, 2026 dict.keys() method in Python returns a view object that contains all the keys of the dictionary. The returned object is dynamic, meaning any changes made to the dictionary are automatically reflected in the view. It is used when only keys are required from a dictionary. Example: In this example, all keys of a dictionary are retrieved using keys().
Output dict_keys(['A', 'B', 'C']) Explanation: d.keys() returns a view object. It contains all keys present in dictionary d.
Syntax
ExamplesExample 1: In this example, the keys() method is used inside a loop to iterate over dictionary keys.
Output A B C Explanation: d.keys() returns all keys and the loop accesses each key one by one. Example 2: In this example, the dynamic nature of the keys() view object is demonstrated.
Output dict_keys(['A', 'B', 'C']) Explanation:
Example 3: In this example, the keys() view object is converted into a list.
Output ['X', 'Y', 'Z'] Explanation: d.keys() returns a view object, list(d.keys()) converts it into a list. This allows indexing or list operations. Related Articles:Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |