- keys() is a python dictionary function which return all the keys of the dictionary.
Syntax-
dict.keys()
Example
dictionary is d={1:'a',2:'b',3:'c'}
d.keys() will return 1,2,3 //keys of d
program-
d=dict()
print("Enter key 1")
n=input()
d.fromkeys(n)
print("Enter value of key 1")
d[n]=input()
print("Enter key 2")
n=input()
d.fromkeys(n)
print("Enter value of key 2")
d[n]=input()
print("Enter key 3")
n=input()
d.fromkeys(n)
print("Enter value of key 3")
d[n]=input()
print("Dictionary is ",d)
print("All keys of dictionary is",d.keys())
print("All keys of dictionary is",*d.keys())
Enter key 1
1
Enter value of key 1
one
Enter key 2
2
Enter value of key 2
two
Enter key 3
3
Enter value of key 3
three
Dictionary is {'1': 'one', '2': 'two', '3': 'three'}
All keys of dictionary is dict_keys(['1', '2', '3'])
All keys of dictionary is 1 2 3