Home > Article > Backend Development > What method of a dictionary returns a list of keys in the dictionary?
In Python, the keys() method of the dictionary can return the "keys" list of the dictionary, and the syntax format is "dict.keys()". The keys() method returns all the keys of a dictionary as a list.
#The operating environment of this tutorial: Windows 7 system, Python 2 version, Dell G3 computer.
Python Dictionary keys() method
The keys() method returns all the keys of a dictionary in a list.
Syntax:
dict.keys()
Return value: Returns all keys of a dictionary.
Example:
#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7} print "Value : %s" % dict.keys()
The output result of the above example is:
Value : ['Age', 'Name']
For more programming-related knowledge, please visit: Programming Learning! !
The above is the detailed content of What method of a dictionary returns a list of keys in the dictionary?. For more information, please follow other related articles on the PHP Chinese website!