# 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. Here i am giving you some method with them you can count the numbers of the keys in dictionary. So lets learn this by given below methods. I hope you guys like it.

## 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() function. By using len() function you can count number of keys in dictionary python. Here we are using len() function with the key(). It will count the key present in the dictionary. For use this method first of all make your dictionary and then print it with the len() function and the key() function.It will give the number of the keys present in your dictionary. Thus you can get the number of the keys. Lets learn this by given below example. lets learn this: `dict1 = {'a1':101,'a2':92,'b1':63,'b2':52,'c1':42,'c2':12,} print(len(dict1.keys()))` Output : `6` You can also use the direct len() function with the dictionary to check out the number of the keys in your dictionary in python. This will return the number of the keys present in your dictionary. This is very easy and simple method. Lets learn how it works by given below example. Lets learn this:
`dict1 = {'a1':101,'a2':92,'b1':63,'b2':52,'c1':42,'c2':12,} print(len(dict1))` Output : `6`

2. How to count number of keys in dictionary python

to count number of keys in dictionary python just Use enumerate(). We can also count the key in dictionary in python. Here we will use enumerate() to count the key in dictionary. Here we will make the dictionary and then use def function with emumerate() and count the number of the keys present in dict. So lets learn this by given below example. `dict1 = {'a1':101,'a2':92,'b1':63,'b2':52,'c1':42,'c2':12,} def countkeys(dict): count = 0 for i in enumerate(dict): count += 1 return count print(countkeys(dict1))` Output : `6`

## Method 1: Use len() function

By using len() function you can count number of keys in dictionary python. Here we are using len() function with the key(). It will count the key present in the dictionary. For use this method first of all make your dictionary and then print it with the len() function and the key() function.It will give the number of the keys present in your dictionary. Thus you can get the number of the keys. Lets learn this by given below example. lets learn this:

``````dict1 = {'a1':101,'a2':92,'b1':63,'b2':52,'c1':42,'c2':12,}
print(len(dict1.keys()))``````

Output :

``6``

You can also use the direct len() function with the dictionary to check out the number of the keys in your dictionary in python. This will return the number of the keys present in your dictionary. This is very easy and simple method. Lets learn how it works by given below example. Lets learn this:

``````dict1 = {'a1':101,'a2':92,'b1':63,'b2':52,'c1':42,'c2':12,}
print(len(dict1))``````

Output :

``6``

## Method 2: Use enumerate()

We can also count the key in dictionary in python. Here we will use enumerate() to count the key in dictionary. Here we will make the dictionary and then use def function with emumerate() and count the number of the keys present in dict. So lets learn this by given below example.

``````dict1 = {'a1':101,'a2':92,'b1':63,'b2':52,'c1':42,'c2':12,}
def countkeys(dict):
count = 0
for i in enumerate(dict):
count += 1
return count
print(countkeys(dict1))``````

Output :

``6``

## Conlusion

Hope all 6 Method Are Useful For You. Comment Below Which Method You Used To Convert String To Datetime In Python. Thank You.