Section 1 - Instruction

We've seen how lists hold collections of items, and how we can add (.append()) or remove (.remove()) items.

Engagement Message

But how can we easily find out exactly how many items are currently inside a list?

Section 2 - Instruction

Every list has a length (or size), which is simply the count of items it contains.

A list like [10, 20, 30] has three items. An empty list [] has zero items.

Engagement Message

Does the length change when we append or remove items?

Section 3 - Instruction

Python provides a built-in function called len() to get the length of a list. It's kind of like print() but only works on lists and returns the length.

You use it like this: len(your_list_variable). It takes the list as input inside the parentheses.

Engagement Message

What kind of value do you expect len() to give back? A string, a number, or something else?

Section 4 - Instruction

The len() function returns an integer representing the number of items.

If colors = ["red", "green", "blue"], then would store the integer in the variable.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal