Exercise 10: len()

Python Len Exercises

Let’s check out some exercises that will help understand len() function better.

Exercise 10-a

Using len() function find out how many items are in the list.

You can pass your object’s name inside len() function:
len(object)

 

answer_1 = len(lst)

Exercise 10-b

len() function can also tell the length of a string.

Find out the length of the string given below.

len(object)

msg_length = len(msg)

Exercise 10-c

How many keys are there in the dictionary?

len(object)

ans_1 = len(dict)

Need More Exercises?

Check out Holy Python AI+ for amazing Python learning tools.

*Includes 14 more programming languages, inspirational tools and 1-on-1 consulting options.
Umut Sagir
Finance & Data Science Professional,
Founder of HolyPython