Get keys from a dictionary in Python

The keys() dictionary method returns a view object which contains the keys of the dictionary, as a list. When the dictionary is updated, keys are also automatically updated to show the changes.

Example:

my_dictionary = {'name': 'Dmitri', 'topic': 'Python', 'fav_food': 'ice cream'}

dict_keys = my_dictionary.keys()
# add a new value
my_dictionary['course'] = 'Python'
# and print the keys after that - they are updated
print(dict_keys)
Output:
dict_keys(['name', 'topic', 'fav_food', 'course'])