Python Dictionary len function is used to return the dictionary length (the total key-value pairs). In this section, we discuss how to use this Python Dictionary len function and the syntax behind this is:
len(dictionary_name)
Python Dictionary len Example
The Python dictionary len function returns the length of a dictionary. The below Python code prints the myDict length.
myDict = {1: 'apple', 2: 'Banana' , 3: 'Orange', 4: 'Kiwi'} print("Dictionary Items: ", myDict) # Dictionary length print("\nThe Dictionary length : ", len(myDict))

In this program, we are going to insert new value to a Dictionary and check the length. Next, we updated a value and displayed the length.
myDict = {'name': 'Kevin', 'age': 25} # Print Total Dictionary print("Dictionary Items : ", myDict) print("The Dictionary length : ", len(myDict)) # Add an Item myDict['job'] = 'Programmer' print("\nDictionary Items : ", myDict) print("The Dictionary length : ", len(myDict)) # Update an Item in Dictionary myDict['name'] = 'Python' print("\nDictionary Items : ", myDict) print("The Dictionary length : ", len(myDict))
Dictionary Items : {'name': 'Kevin', 'age': 25}
The Dictionary length : 2
Dictionary Items : {'name': 'Kevin', 'age': 25, 'job': 'Programmer'}
The Dictionary length : 3
Dictionary Items : {'name': 'Python', 'age': 25, 'job': 'Programmer'}
The Dictionary length : 3