The keys Method in Python: Dictionary Keys

The keys method returns dictionary keys as a sequence. This sequence can be used to iterate over the dictionary or to create a new dictionary.

keys()

data = {'one': 1, 'two': 2, 'three': 3}

for key in data.keys():
    print(key)

You can also iterate through dictionary keys without using the keys() method:

data = {'one': 1, 'two': 2, 'three': 3}

for key in data:
    print(key)