Home  >  Article  >  Backend Development  >  What method of a dictionary returns a list of keys in the dictionary?

What method of a dictionary returns a list of keys in the dictionary?

青灯夜游
青灯夜游Original
2021-01-29 17:45:1222114browse

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.

What method of a dictionary returns a list of keys in the dictionary?

#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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn