Work With Lists of Numbers
It’s not uncommon that you’ll have to work with a list of numbers. For example, here we have our
numbers list again. This time it goes all the way up to five, so it contains the integers from one through five.
You could define a variable outside of the loop that’s going to hold the total. So I’m going to say
total = 0 to initialize the variable, and then start a
for loop where I’m going to say
for number in numbers
00:55 This is a way you can do it, but Python has some tools that make operations like this one faster and easier because you can perform some mathematical operations on collections using built-in functions.
03:03 In this lesson, you’ve learned how you can work with lists of numbers using some common built-in Python functions. In the next lesson, you’ll look at something quite powerful and interesting called list comprehensions.
Become a Member to join the conversation.