The keys( ) Function is used to Iterate a 'Dictionary' and display the 'Keys' .
x = {
5 : "Is a Number",
"John": "Is a Name",
"Python": "Is a Language"
}
for i in x.keys():
print(i)
So , in the above code we have created a 'Dictionary' using braces '{ }' and 'Key' and 'Value' pairs.
x = {
5 : "Is a Number",
"John": "Is a Name",
"Python": "Is a Language"
}
And initialised to the variable 'x' .
Function1.png)
In the next line we have used the 'for loop' to Iterate through the 'Dictionary' just to get the 'Keys' .
for i in x.keys():
print(i)
Now , since there is a 'Key' and 'Value' pair in a 'Dictionary' , we have used the 'keys( )' Function, that will only print the 'Keys' and not the 'Values' .
And if you see the Output , just the 'Keys' are printed.