Python Dictionary len() Method
Description
The Python Dictionary len() function calculates the number of dictionary elements, i.e., the total number of keys.
Syntax
Syntax of the len() method:
len(dict)
Parameters
- dict -- The dictionary whose number of elements is to be calculated.
Return Value
Returns the number of elements in the dictionary.
Example
The following example demonstrates how to use the len() function:
Example
#!/usr/bin/python
tinydict = {'Name': 'Example', 'Age': 7};
print "Length : %d" % len (tinydict)
tinydict = {'Name': 'Example', 'Age': 7};
print "Length : %d" % len (tinydict)
The output of the above example is:
Length : 2Other Extensions
Python Dictionary