The keys method
The keys method returns the dictionary keys. The keys are returned as a special object dict_keys. We do not specify anything in the method parameter.
Syntax
dictionary.keys()
Example
Let's find all the keys in our dictionary:
dct = {
'a': 1,
'b': 2,
'c': 3
}
print(dct.keys())
Result of code execution:
dict_keys(['a', 'b', 'c'])
Example
Let's get the keys as a list:
dct = {
'a': 1,
'b': 2,
'c': 3
}
print(list(dct.keys()))
Result of code execution:
['a', 'b', 'c']