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

Python Dictionary len() method

Python Dictionary len() method

Python Dictionary Python Dictionary


Description

The Python Dictionary len() function counts the number of elements in a dictionary, that is, the total number of keys.

Syntax

len() method syntax:



len(dict)

Parameters

Return Value

Returns the number of elements in the dictionary.

Example

The following example shows how to use the len() function:

Example

#!/usr/bin/python

tinydict

=

{

'Name'

:

'Runoob'

,

'Age'

:

7

}

;

print

"Length : %d"

%

len

(

tinydict

)

The output of the above example is:



Length : 2

Python Dictionary Python Dictionary