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

青灯夜游
Release: 2022-12-30 11:13:05
Original
22173 people have browsed it

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()
Copy after login

Return value: Returns all keys of a dictionary.

Example:

#!/usr/bin/python
dict = {'Name': 'Zara', 'Age': 7}
print "Value : %s" %  dict.keys()
Copy after login

The output result of the above example is:

Value : ['Age', 'Name']
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template