A cargo pod docks with a soft thump. Rocket starts typing a variable for each thing inside it: cargo1, cargo2, cargo3, cargo4. By cargo9, his fingers are tired.
"There must be a faster way," he sighs.
Raven floats over to read the screen. "What do you notice about all these names?" she asks. "They are all cargo," Rocket says. "Only the number changes."
Nova draws a long glowing shelf in the air. "Would you like a hint? One name can hold a whole row of values."
A list keeps many values in order under one name.
Square brackets [ ] hold the list. Commas go between the items.
cargo = ["water", "oats", "tools"] fuel = [30, 45, 20] print(cargo) print(fuel)
| The screen shows |
|---|
| ['water', 'oats', 'tools'] |
| [30, 45, 20] |
| List | Does it hold exactly 3 items? |
|---|---|
| [4, 8, 15] | ? |
| ["oats", "rice"] | ? |
| ["a, b, c"] | ? |
| ["red", "blue", "green"] | ? |
crew = ["Rocket", "Raven"] print(crew)
kit = ["rope", "lamp", "tape"] nums = [12, 7, 30, 5] print(kit) print(nums)
| Statement | True or false? |
|---|---|
| [5, 10] holds 2 items. | ? |
| A list can only hold numbers. | ? |
| ["one"] holds 1 item. | ? |
| [ ] holds 1 item. | ? |
Great job! You made your first lists. Tomorrow you will reach into a list and grab one item.