close

How to count Number of Keys in Dictionary Python

Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about how to count Number of Keys in Dictionary Python. so without wasting time lets learn about of this.

How to count Number of Keys in Dictionary Python

  1. count Number of Keys in Dictionary Python

    to count Number of Keys in Dictionary Python just use len() By using len() you can count Number of Keys in Dictionary Python. Lets learn this by below example:
    dict1 = {'R1' : 45,'R2' : 48,'R3' : 50} print(len(dict1.keys())) Output : 3

  2. How to count Number of Keys in Dictionary Python

    to count Number of Keys in Dictionary Python just use enumerate() By using enumerate() you can count Number of Keys in Dictionary Python. Lets learn this by below example: dict1 = {'R1' : 45,'R2' : 48,'R3' : 50} def count_keys(dict): count = 0 for i in enumerate(dict): count += 1 return count print(count_keys(dict1)) Output : 3

  3. python dictionary count

    to count Number of Keys in Dictionary Python just use enumerate() By using enumerate() you can count Number of Keys in Dictionary Python. Lets learn this by below example: dict1 = {'R1' : 45,'R2' : 48,'R3' : 50} def count_keys(dict): count = 0 for i in enumerate(dict): count += 1 return count print(count_keys(dict1)) Output : 3

Method 1: Using len()

By using len() you can count Number of Keys in Dictionary. Lets learn this by below example:

dict1 = {'R1' : 45,'R2' : 48,'R3' : 50}
print(len(dict1.keys()))

Output :

3

Method 2: Using enumerate()

By using enumerate() you can count Number of Keys. Lets learn this by below example:

dict1 = {'R1' : 45,'R2' : 48,'R3' : 50}
def count_keys(dict):
    count = 0
    for i in enumerate(dict):
        count += 1
    return count
print(count_keys(dict1))

Output :

3

Conclusion

It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?

Also, Read

Leave a Comment