len() in Python Dictionary

It is a function in python dictionary that returns the number of key-value pair in the given dictionary. It returns an integer type value.

Syntax:

len(dictionary)

Example 1:

s = {0:"CodeWindow", 1:"India", 2:"News"}
x = len(s)
print(x)

Output:

3

Explanation:

Here there is 3 key-value pairs present in the dictionary. Hence it returned 3.

Example 2:

s = {"site":"CodeWindow", "country":"India", "type":"News", "platform":"IT"}
x = len(s)
print(x)

output:

4

Explanation:

Here there is 4 key-value pairs present in the dictionary. Hence it returned 4.


You Missed

Also Checkout