Home >>Python Dictionary Methods >Python Dictionary keys() Method

Python Dictionary keys() Method

Python Dictionary keys() Method

Python Dictionary keys() Method in python dictionary is used to returns a list of keys and fetch all the keys from the dictionary.

Syntax:
dictionary.keys()
Here is an example of Python Dictionary keys() Method:

colors = {
"color1": "white",
"color2": "blue",
"color3": "green"
}
z = colors.keys()
print(z)

Output:
dict_keys(['color1', 'color2', 'color3'])
Example 2:

prdct = {'name':'mobile','brand':'MI','price':25000}   
for p in prdct.keys():  
if p == 'price' and prdct[p] > 15000:  
print(" price is too high",)  

Output:
price is too high