Python dictionary len() Method


Contents

Description

len() is a constructed default function in python. Users could utilize the len() to obtain the length of the provided string, array, list, tuple, dictionary, etc. The provided value that user require the length of. Return worth a go back an integer value i.e. the length of the supposed string, or array, or list, or collections Python dictionary method len() offers the total length of the lexicon. This would be equivalent to the figure 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/python

dict = {'Name': 'Zara', 'Age': 7};
print "Length : %d" % len (dict)

When we run above program, it produces following result:

Length : 2

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.



Navigation
Tutorial
Tutorial
Tutorial