Python Dictionary keys function

Python keys function is used to return the list of available total keys in a dictionary. In this section, we discuss how to use this Dictionary keys function, and the syntax behind this is:


Python Dictionary keys function Example

It returns the list of keys available in a given one. The below code prints the keys in emp and empl.

TIP: Please refer to the Dictionary to understand them in Python.

emp = {'name': 'Kevin', 'age': 25 , 'job': 'HR', 'Sal': 725000}
print("Dictionary: ", emp)

# Print
print("\nDictionary Keys: ", emp.keys())

# Creating an Empty Dictionary
empl = {}
print("Dictionary: ", empl)

# Print
print("\nDictionary Keys: ", empl.keys())
Python Dictionary keys function 1

In this program, we are going to insert a new value into the dict and print keys. Next, we updated a value and displayed the keys.

emp = {'name': 'Kevin', 'age': 25 , 'job': 'HR'}


emp['age'] = 27

emp['Sal'] = 725000
{'name': 'Kevin', 'age': 25, 'job': 'HR'}

dict_keys(['name', 'age', 'job'])

dict_keys(['name', 'age', 'job'])

dict_keys(['name', 'age', 'job', 'Sal'])