can u length a dictionary in python 1

can u length a dictionary in python

obj = {0:"hello", 1:"there"}

for i in range(len(obj)):
  print(obj[i])
  
print(len(obj))

Here is what the above code is Doing:
1. We create a dictionary called obj.
2. We create a for loop that iterates through the length of the dictionary.
3. We print the value of the dictionary at the index of the for loop.
4. We print the length of the dictionary.

The output of the above code is:
hello
there
2

The length of the dictionary is 2.

Similar Posts