Python Dictionary keys() Method

Python 字典Python Dictionary


Description

Python dictionary keys() function returns all the keys of a dictionary as a list.

Syntax

Syntax of the keys() method:

dict.keys()

Parameters

  • NA。

Return Value

Returns all the keys of a dictionary.

Example

The following example demonstrates the usage of the keys() function:

Example

#!/usr/bin/python

tinydict = {'Name': 'Zara', 'Age': 7}

print "Value : %s" %  tinydict.keys()

The output of the above example is:

Value : ['Age', 'Name']

Python 字典Python Dictionary

Other Extensions