0
0
Pythonprogramming~10 mins

len() function in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Counting Items with the len() Function
๐Ÿ“– Scenario: You are organizing a small library. You want to know how many books you have on your shelf.
๐ŸŽฏ Goal: Learn how to use the len() function to count the number of items in a list.
๐Ÿ“‹ What You'll Learn
Create a list of book titles
Create a variable to store the count of books
Use the len() function to find the number of books
Print the number of books
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Counting items is useful in many daily tasks like inventory, lists, or checking how many things you have.
๐Ÿ’ผ Career
Knowing how to count items in data is a basic skill for programming jobs, data analysis, and software development.
Progress0 / 4 steps
1
Create a list of books
Create a list called books with these exact titles: 'The Hobbit', '1984', 'Pride and Prejudice', 'To Kill a Mockingbird'.
Python
Need a hint?

Use square brackets [] to create a list and separate items with commas.

2
Create a variable to hold the count
Create a variable called book_count and set it to 0 to prepare for counting.
Python
Need a hint?

Just write book_count = 0 on a new line.

3
Use len() to count the books
Set book_count to the length of the books list using the len() function.
Python
Need a hint?

Use len(books) to get the number of items in the list.

4
Print the number of books
Print the value of book_count to show how many books are on the shelf.
Python
Need a hint?

Use print(book_count) to display the number.