Lists
7 min · Python
Hold many values under one name, and reach for the one you want.
A list holds several values in order, inside square brackets, separated by commas. One name, many values.
Run this to make a list of fruits and print the whole thing.
Try it yourself
Loading editor...
Ln 1, Col 1Spaces: 4
Sign up to run itExpected output: ['apple', 'banana', 'cherry']
Reach for one item by its position
Each item has a position called an index, and counting starts at 0 — so the first item is index 0, the second is index 1, and so on.
Grow the list
Add a new item to the end with .append(). And len() counts the items, just like it counted characters in a string.
Your turn
Make a list called colors holding "red", "green", "blue", then print the last one: blue