Tutorpip← About this lessonOpen the sheet →Download PDF
Ages 8+ · Coding · Variables and data
Lists of things
Box number• box 0• box 1• box 2• box 3• box 4Treasure• star• moon• sun• cloud• bolt
Five treasure boxes, counted from zero.
The big ideaA list is a row of numbered boxes, and the first is number zero.

How it works

A list is a row of numbered boxes. Things kept in order make a list.

Each box has a place number called an index, and the first box is number zero.

So the third box is number two, and five boxes run from zero up to four.

A list can grow: a new box joins at the end, and the old boxes keep their numbers.

1st box:index 02nd box:index 13rd box:index 24th box:index 35th box:index 4
Counting from zero.

Example 1: Which box?

  1. The list is star, moon, sun, cloud, bolt.
  2. Mina wants the sun, which is the third treasure.
  3. Counting from zero, the sun is box number two.

Example 2: The wrong number

  1. Mina asks for box number three, and out pops the cloud, the fourth treasure.
  2. She wanted the sun, so she should have asked for index two.

Example 3: The last index

  1. There are five boxes: 0, 1, 2, 3 and 4.
  2. The last index is four, one less than the five boxes.

Example 4: A list grows

  1. Tavi adds a new treasure on the end, at index five.
  2. The old boxes keep their numbers.
  3. Now six boxes run from zero up to five.

Example 5: A swap

  1. Mina swaps the moon for a heart.
  2. The moon was in box one, so box one now holds the heart.
  3. The box keeps its number, and only what is inside it changes.

Words to know

list
A row of numbered boxes.
index
A box's place number, counted from zero.
box
One place in the list that holds one thing.

Watch out

Try it

  1. Which box holds the first thing in a list?
  2. A list has five things. What is the index of the last one?
  3. In the list star, moon, sun, cloud, bolt, what is in box 3?
  4. What is the index of the moon?
  5. A new treasure joins a list of five at the end. Which index does it get?
Answers: 1. Box 0 · 2. 4 · 3. The cloud · 4. 1 · 5. 5
Try at homeLine up five small things in a row, like a coin, a button, a spoon, a sock and a pen. Stick a paper number on each place, starting at zero. Ask a grown-up to say a number, and you hand them the thing at that place. Then swap two things and try again.
For grown-upsPlay the Mission: line up five small things in a row, like a coin, a button, a spoon, a sock and a pen, with a paper number on each place starting at zero. Say a number and your child hands you the thing at that place. Then swap two things and try again.
Open these notes on screenScan the code, or go to tutorpip.com.