Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Dictionary keys() method

Python Dictionary keys() method

Python Dictionary Python Dictionary


Description

The Python Dictionary keys() function returns a list of all the keys in a dictionary.

Syntax

keys() method syntax:



dict.keys()

Parameters

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

}

print

"Value : %s"

%  tinydict.

keys

(

)

The output of the above example is:



Value : ['Age', 'Name']

Python Dictionary Python Dictionary