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
Calculate the length of long_list
and save it to the variable long_list_len
.
Use print()
to examine long_list_len
.
We have provided a completed range()
function for the variable big_range
.
Calculate its length using the function len()
and save it to a variable called big_range_length
.
Note: Range objects do not need to be converted to lists in order to determine their length
Use print()
to examine big_range_length
.
Change the range()
function that generates big_range
so that it skips 100
instead of 10
steps between items.
How does this change big_range_length
?