Python Dictionary len() method
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
- dict -- the dictionary whose elements are to be counted.
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
}
;
"Length : %d"
%
len
(
tinydict
)
The output of the above example is:
Length : 2
Python Dictionary