Free cookie consent management tool by TermsFeed Python Dictionary - len() function | Pythontic.com

Python Dictionary - len() function

Function Name:

len(dict_in)

Parameters:

dict_in - The dictionary for which the number of elements present to be counted.

Function overview:

  • The len() function returns the number of elements stored in a Python dictionary object.
  • For an empty dictionary the len() function returns zero.

Parameters:

dict_in _ a dictionary object for which number of items to be determined.

Example:

# Example Python program that finds the total number
# of items present in a Python dictionary
d = {"a":1, "b":2, "c":3}
elemCount = len(d)
print("Number of elements:")
print(elemCount)

Output:

Number of elements:
3

 


Copyright 2025 © pythontic.com