Languages
[Edit]
EN

Python - get dictionary keys

3 points
Created by:
Nataniel-Barclay
289

In this article, we would like to show you how to get dictionary keys in Python.

Quick solution:

my_dictionary.keys()

 

Practical example

In this example, we use keys() method to get the list of my_dict dictionary keys.

my_dict = {
    "id": 1,
    "name": "Tom",
    "age": 25
}
result = my_dict.keys()

print(result)  # dict_keys(['id', 'name', 'age'])

Output:

dict_keys(['id', 'name', 'age'])
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join