← VCE Software Development U3O1

Two-dimensional arrays

A 2D array stores data in rows and columns like a table. Use the row index first, then the column index, to reach one element, such as a seat in a seating plan.

Understanding Two-dimensional arrays in VCE Software Development U3O1

What it does: The outer list holds the rows, so len(timetable) counts how many rows the grid has. board[1][2] selects row 1, column 2, and assigning to it replaces that single cell with the new value. A two-dimensional array is like a table or grid, with rows going across and columns going down. The row index always comes first, then the column index: seats[row][col]. A 2D array in Python is a list of lists. Each inner list is one row, and here each row holds 3 columns. Rows x columns = 3 x 3 = 9 elements. Adding them (3 + 3) is a common mistake.

Common mistakes: Each row has 3 columns, so valid column indexes are 0, 1 and 2. Column 3 gives an IndexError. It should be col = 2. The outer list is missing its closing bracket, so the board is a syntax error. The line should end with ]] so both rows are inside the outer list.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 72–96) and word search (Modules 72–113).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A 2D array stores data in...
A single line of values onlyRows and columns, like a table
Matches
seats = [["Ava", "Liam"], ["Mia", "Noah"]] print(seats[0, 1])
↓
Both indexes are put in one set of square brackets. Each index needs its own brackets, so use seats[0][1].
Applying
Meanings
Term
grid[row][col]
Meaning
A 2D array stores data in rows and columns like a table. Use the row index first, then the column index, to reach one element, such as a seat in a seating plan.
Practice
seats = [["Ava", "Liam"], ["Noah", "Zoe"]]
Testing
Gaps
print(grid[][2]) # second row, third column
Check Answer
Spots
2row = 1
3col = 3

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Camel' badge — Endurance Champion, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A 2D array stores data in...
A. A single line of values only
B. Rows and columns, like a table ✓
A two-dimensional array is like a table or grid, with rows going across and columns going down.
2. Which gets the element in row 2, column 3 of a seating plan?
A. seats[3][2]
B. seats[2][3] ✓
The row index always comes first, then the column index: seats[row][col].
3. In grid[1][4], what does the 4 represent?
A. The column index ✓
B. The row index
The second index is the column. The first index, 1, is the row.
4. Which Python code creates a 2D array with 2 rows and 3 columns?
A. grid = [[0, 0, 0], [0, 0, 0]] ✓
B. grid = [0, 0, 0, 0, 0, 0]
A 2D array in Python is a list of lists. Each inner list is one row, and here each row holds 3 columns.
5. A game board has 3 rows and 3 columns. How many elements does it hold?
A. 9 ✓
B. 6
Rows x columns = 3 x 3 = 9 elements. Adding them (3 + 3) is a common mistake.

Match the Pairs

seats[2][0] → Gets the element in row 2, column 0 of the seating plan: row index first, then column index
board = [["X", "O"], ["O", "X"]] → Creates a 2D array for a game board with 2 rows and 2 columns, as a list of row lists
Each row of a timetable is an inner list, so len() of the outer list gives the number of rows → rows = len(timetable)
Change one cell of a game board by giving its row index first, then its column index → board[1][2] = "X"
seats = [["Ava", "Liam"], ["Mia", "Noah"]] print(seats[0, 1]) → Both indexes are put in one set of square brackets. Each index needs its own brackets, so use seats[0][1].
timetable = [["Maths", "English"], ["Art", "PE"]] print(timetable[2][0]) → The row index 2 is out of range because there are only 2 rows, numbered 0 and 1. Use timetable[1][0] to get Art.

Key Term

grid[row][col]
A 2D array stores data in rows and columns like a table. Use the row index first, then the column index, to reach one element, such as a seat in a seating plan.

Fill in the Blanks

1. grid = [[1, 2, 3], [4, 5, 6]] print(grid[1][2]) # second row, third column
Hint: Type the row index for the second row (counting from 0).
2. board = [["X", "O"], ["O", "X"]] print(board[0][1 ]) # first row, second column
Hint: Type the column index for the second column (counting from 0).
3. board = [["-", "-"], ["-", "-"]] board[1][0] = "X" print(board)
Hint: Type the name of the 2D array variable being changed.
4. for r in range(len(grid)): for c in range(len(grid[r])): print(grid[r][c])
Hint: Type the function that counts how many rows are in the grid.
5. board = [["X", "O"], ["O", "X"]] if board[0][0] == "X": print("Top left is X")
Hint: Type the comparison operator that checks if two values are equal.

Spot the Error

Question 1
A grid = [[1, 2, 3], [4, 5, 6]]
B row = 1
C col = 3
D print(grid[row][col])
Line C — Each row has 3 columns, so valid column indexes are 0, 1 and 2. Column 3 gives an IndexError. It should be col = 2.
Question 2
A board = [["X","O"],["O","X"]
B row = 0
C col = 1
D print(board[row][col])
Line A — The outer list is missing its closing bracket, so the board is a syntax error. The line should end with ]] so both rows are inside the outer list.
Question 3
A plan = [[0, 0, 0], [0, 0, 0]]
B plan[1, 2] = 5
C print(plan[1][2])
Line B — Python lists need one pair of brackets per index: the row first, then the column. plan[1, 2] causes a TypeError. It should be plan[1][2] = 5.
Question 4
A grid = [[1, 2], [3, 4]]
B total = 0
C for r in range(2):
D for c in range(3):
E total += grid[r][c]
Line D — Each row has only 2 columns, so the inner loop must use range(2). range(3) makes c reach 2 and causes an IndexError.
Question 5
A board = [["X","O"],["O","X"]]
B board[0][1] = X
C print(board[0][1])
Line B — The text X needs quotes, otherwise Python looks for a variable called X and raises a NameError. It should be board[0][1] = "X".

Student with a class code? Join your class →