Python Dictionary keys() method
Description
The Python Dictionary keys() function returns a list of all the keys in a dictionary.
Syntax
keys() method syntax:
dict.keys()
Parameters
- NA.
Return Value
Returns all the keys in a dictionary.
Example
The following example shows how to use the keys() function:
Example
#!/usr/bin/python
tinydict
=
{
'Name'
:
'Zara'
,
'Age'
:
7
}
"Value : %s"
% tinydict.
keys
(
)
The output of the above example is:
Value : ['Age', 'Name']
Python Dictionary