Python 3 - dictionary len() Method


Advertisements

Description

The method len() gives the total length of the dictionary. This would be equal to the number of items in the dictionary.

Syntax

Following is the syntax for len() method −

len(dict)

Parameters

dict − This is the dictionary, whose length needs to be calculated.

Return Value

This method returns the length.

Example

The following example shows the usage of len() method.

#!/usr/bin/python3

dict = {'Name': 'Manni', 'Age': 7, 'Class': 'First'}
print ("Length : %d" % len (dict))

Result

When we run above program, it produces the following result −

Length : 3
python_dictionary.htm
Advertisements