GCSE · Computer Science · OCR · Spec J277

1D arrays

Four friends stored under one name: players. Ask for players[1] and you get Ben, not Ana. If that feels wrong, good. That's exactly the bit this lesson sorts out.

Computer Science · Arrays

Two loops, one array

Four names stored under one name, players. Step through two different loops over the same array and watch what each one actually gets hold of.

Before you press Next: Cal is the third name. What index do you think Cal is at?

1 players = ["Ana", "Ben", "Cal", "Dev"]
2 for player in players:
3 print(player)
4 for i in range(len(players)):
5 print(i, players[i])
playeriplayers[i]

Output

 

Step 1: One name, four items. Here a Python list is being used as an array: four slots, every item a string, and that length and data type stay fixed.

1 / 9

Each row is one pass of a loop. The player column fills during loop 1; i and players[i] fill during loop 2.

Step 1 of 9: One name, four items. Here a Python list is being used as an array: four slots, every item a string, and that length and data type stay fixed..

Watch out: The first item is at index 0. So players[1] is Ben, the second name, not Ana.

Computer Science · Indexes

Where does counting start?

marks = [14, 9, 17, 11] is being used as an array. Four students explain how to reach the items in it.

Which one is closest to what you think right now?
How sure are you?

Array or list?

ArrayvsList

Start with the Size row. It's the headline difference.

Focus

Size

Array

Static. Memory is reserved for a set amount of data, so the size is fixed.

List

Dynamic. It can change size as items are added or deleted.

The insight

If you remember one row, make it this one: static versus dynamic.

Data types

Array

Every item must be the same data type.

List

Can hold items of different data types.

Changing an item

Array

Allowed. You can change what an item holds.

List

Allowed.

Adding or deleting items

Array

Not allowed.

List

Allowed. That's what makes it dynamic.

Reaching an item

Array

By its index, starting at 0.

List

By its index, starting at 0.

Computer Science · Change, don't add

Five readings, one rule broken

temps is a list being used as an array: five readings, all whole numbers, length fixed. Which line breaks the rules of an array?

A classmate's program — which line goes wrong?

Computer Science · Choosing a data structure

Would an array do the job?

Three checks: Do you know how many items there are at the start? Will items need adding or removing? Is all the data one type?

Still to sort

An array suits this (0)

Passes all three checks.

Where the line is: Changing a value later doesn't rule out an array. Only adding or removing items does.

An array doesn't suit this (0)

Fails at least one check.

Where the line is: One failed check is enough: an unknown number of items, items added or removed, or mixed data types.

6 of 6 still to sort.

Six jobs. Run the three checks on each one before you place it.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

A row of numbered slots under one name. You can change what's in a slot, but you can't add a new one. And the numbering starts at 0.

What you need to know

  • An array stores lots of items under one name, keeping your data organised and easy to get at.
  • Each item sits at an index, which is simply its position.
  • Indexing is zero-based: the first item is at index 0, not 1.
  • Have a gocolours = ["red", "green", "blue"]. Your mate swears colours[1] is "red" and is willing to bet their lunch on it. Before you look: what's really at index 1?

    "green". Your mate owes you lunch.

    "red" is at index 0, because counting starts at 0, so index 1 is the second item. Your mate counted from 1.

  • You access an item by giving its index, like players[2]; an expression such as i + 1 works too, if it gives an integer.
  • Have a goSame colours array, and i holds 1. Which item does colours[i + 1] give you?

    "blue"

    i + 1 works out to 2, an integer, so it's used as the index, and index 2 is the third item. "green" comes from using i and forgetting the + 1.

  • An array is static: it reserves memory for a set amount of data, so its size can't change.
  • Every item in an array has to be the same data type.
  • You can change what an item holds, but you can't add items or delete them.
  • Have a goAn array holds [5, 8, 3]. Which of these is allowed: changing the 8 into a 9, or putting a 4 on the end?

    Changing the 8 into a 9.

    An array's contents can be changed, but its size is fixed, so a fourth item can't be added.

  • A list is different: it's dynamic, can grow or shrink, and can hold mixed data types.
  • In Python, a list can act as an array, provided its length and data type stay fixed.
  • Visit every item with for item in array, or with for i in range over its length, using i as the index.

The big picture

An array holds multiple items of one data type under one name. It's static: its size is fixed, so you can change items but not add or delete them. Each item has an index, starting at 0, and an index can be any expression that works out to an integer. You can visit every item with for item in array, or with for i in range over the array's length, using i as the index. A list, by contrast, is dynamic and can hold mixed data types.

Key points

1An array is a static data structure: one name, a fixed number of items, all of the same data type.
2Items are accessed by index, starting at 0; an index can be any expression that evaluates to an integer.
3An array's contents can be changed, but items can't be added or deleted. A list is dynamic, can change size and can mix data types.
4An array suits a job when the number of items is known at the start, nothing needs adding or removing, and all the data is one type.
5for item in array gives you each item in turn; for i in range over the array's length gives you each index, and array[i] fetches the item.

Worked example

Problem

speeds = [30, 40, 50, 60, 70] is a list being used as an array. A program runs i = 2, then speeds[i + 1] = 45, then print(speeds[i - 2]) and print(speeds[4]). What gets printed, and what does speeds hold at the end?

⚠ Watch out

Counting from 1. In an array of 5 items the first is at index 0 and the last at index 4, so array[1] is the second item, and array[5] isn't one of its items at all.

🧠

Memory hook

A fixed row of numbered boxes: you can swap what's in a box, but you can't add a box. And the first box is box 0.

✓

Check yourself

Cover the page. Give three ways an array differs from a list. Then, for nums = [4, 8, 15, 16], say which item nums[2] gives you and which index holds 16.

Flashcards

(14)
What is an array?
A data structure that holds multiple items under one name, storing data in an organised and accessible way.
Why is an array called a static data structure?
It reserves a fixed amount of memory for a set amount of data, so its size is fixed and can't change.
What rule do all the items in an array follow about data type?
They must all be the same data type.
In an array, can you change an item? Can you add or delete one?
Changing an item's contents: yes. Adding or deleting items: no.
What is an item's index?
Its position in the array. You use it to access the item.
At which index is the first item of an array?
Index 0. Indexing is zero-based.
An array has 6 items. What are its first and last indexes?
0 and 5.
Can an expression be used as an index?
Yes, as long as it evaluates to an integer. For example, nums[i + 1] when i is a whole number.
How does a list differ from an array in size?
A list is dynamic: it can change size as items are added or deleted. An array's size is fixed.
How does a list differ from an array in data types?
A list can hold items of different data types; an array's items must all be one type.
When is an array a suitable choice?
When the number of items is known at the start, no items need adding or removing, and all the data is the same type.
In for item in array, what does the variable hold each time round?
Each item of the array in turn.
In for i in range over an array's length, what values does i take, and what is it for?
0, 1, 2 and so on, one per item. It's used as the index, so array[i] is the item at that position.
When can a Python list be used as an array?
When its length and the data type of its items stay fixed.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More OCR GCSE Computer Science topics

See the full OCR Computer Science curriculum →

How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 3 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.