Learn

Often, we’ll need to find the number of items in a list, usually called its length.

We can do this using a built-in function called len().

When we apply len() to a list, we get the number of elements in that list:

my_list = [1, 2, 3, 4, 5] print(len(my_list))

Would output:

5

Let’s find the length of various lists!

Instructions

1.

Calculate the length of long_list and save it to the variable long_list_len.

2.

Use print() to examine long_list_len.

3.

We have provided a completed range() function for the variable range_list.

Calculate its length using the function len() and save it to a variable called range_list_length.

Note: Range objects do not need to be converted to lists in order to determine their length

4.

Use print() to examine range_list_length.

5.

Change the range() function that generates range_list so that it skips 100 instead of 10 steps between items.

How does this change range_list_len?

Sign up to start coding

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Already have an account?