Open links in new tab
  1. The keys() method in Python is used to extract the keys of a dictionary and returns them as a view object. This view object reflects any changes made to the dictionary.

    Example

    car = {
    "brand": "Ford",
    "model": "Mustang",
    "year": 1964
    }
    x = car.keys()
    print(x) # Output: dict_keys(['brand', 'model', 'year'])
    Copied!

    Usage

    The keys() method does not take any parameters and is used as follows:

    dict.keys()
    Copied!

    Here, dict is the dictionary whose keys are to be extracted.

    Dynamic Updates

    The view object returned by keys() gets updated if the dictionary is modified.

    car["color"] = "white"
    print(x) # Output: dict_keys(['brand', 'model', 'year', 'color'])
    Copied!

    Practical Application

    You can use the keys in loops or convert them into a list for further operations.

    for key in car.keys():
    print(key)
    # Output:
    # brand
    # model
    # year
    # color

    keys_list = list(car.keys())
    print(keys_list) # Output: ['brand', 'model', 'year', 'color']
    Copied!

    Note: The keys() method provides a dynamic view, meaning any changes to the dictionary will be reflected in the view object.

  1. Python Dictionary keys () method - GeeksforGeeks

    Feb 17, 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 …

  2. People also ask
    Loading
    Unable to load answer
  3. Python Dictionary keys () (With Examples) - Programiz

    • Output In the above example, we have used the keys()method to extract the keys of the dictionary. The list of keys are returned as a view object. Here, dict_keys() is the view object and ['name', 'age', 'salary'] is the list of keys of the dictionary employee.
    See more on programiz.com
  4. Understanding the `.keys ()` Method in Python — codegenes.net

    Jan 16, 2026 · In Python, dictionaries are one of the most powerful and widely used data structures. They allow you to store and retrieve data using key-value pairs. The `.keys ()` method is a built-in …

  5. How To Get Keys Of A Dictionary In Python?

    Feb 18, 2025 · Learn how to get the keys of a dictionary in Python using the `keys ()` method, loops, and list comprehensions to efficiently access and manipulate …

  6. Python Dictionary Keys: Guide & Examples - PyTutorial

    Jan 27, 2026 · Learn everything about Python dictionary keys, including creation, access, immutability rules, and key methods for efficient data handling.

  7. Valid Python dictionary keys

    Newcomers to Python often wonder why, while the language includes both a tuple and a list type, tuples are usable as dictionary keys, while lists are not. This was a deliberate design decision, and can best …

  8. keys — Python Function Reference

    A comprehensive guide to Python functions, with examples. Find out how the keys function works in Python. Returns a new list of the dictionary's keys.

  9. Unlocking the Power of Keys in Python - CodeRivers

    Mar 18, 2025 · This blog post will dive deep into the fundamental concepts of keys in Python, explore different usage methods, discuss common practices, and provide best practices to help you make the …

  10. Python Dictionary keys () Method: A Complete Guide

    May 20, 2025 · In this guide, we‘ll explore everything you need to know about the keys() method – from basic usage to advanced techniques that will help you write cleaner, more efficient Python code.