Module 3 · Lists and list processing · Lesson 1 of 7
What are lists?
Imagine storing four test scores. You could make four variables — score1, score2, and so on — but that gets unbearable fast. What if there are a thousand? A list holds as many values as you like under a single name, kept in order.
scores = [85, 92, 78, 64]
You write one with square brackets and commas: [85, 92, 78, 64]. The values keep the order you put them in, and len() tells you how many there are. A list can even hold a mix of types — numbers, strings, booleans, all together — though most of the time they'll be the same kind of thing.
That last one, [], is an empty list — perfectly valid, and the usual starting point when you're about to build a list up piece by piece. Now that you have a row of values, the next question is how to reach into it.