Lesson 16 of 34
Lists: Many Values in One Place
9 min 25 XP
You don't need 40 variables for 40 students' marks! A list holds many values in order. Write them inside [ ] separated by commas.
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.You can change an item using its index. Slicing [start:stop] gives part of a list (stop is not included).
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.A for loop visits every item in a list.
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.A list can mix types: [1, "two", 3.0, True]