Python: tables with 2D lists

A game board, a seating plan and a class mark book are all tables: rows and columns. In Python you can store a table as a list of lists.

Practise this lesson free (6 questions)

A list of lists

Each item in the outer list is itself a list: one row.
scores = [[5, 8, 6],
          [9, 7, 10],
          [4, 6, 7]]
This is called a two-dimensional (2D) list. Other languages call it a 2D array.
scores as a table: scores[row][column]
Round 0Round 1Round 2
Player 0586
Player 19710
Player 2467

Row first, then column

To reach one item, give the row index, then the column index, both starting at 0.
scores = [[5, 8, 6],
          [9, 7, 10],
          [4, 6, 7]]
print(scores[1][2])
print(scores[0][1])
Output:
10
8
len(scores) gives the number of rows (3); len(scores[0]) gives the number of columns in row 0 (3).

Nested loops

A loop inside a loop visits every item, row by row.
scores = [[5, 8, 6],
          [9, 7, 10],
          [4, 6, 7]]
for row in scores:
    total = 0
    for s in row:
        total = total + s
    print(total)
Output:
19
26
17
These are the total scores for each player. You can also change an item: board[2][2] = "X".
Worked example

What does this print?
board = [["X", "O", "X"],
         [" ", "X", "O"],
         ["O", " ", " "]]
board[2][2] = "X"
print(board[2])

  1. board[2] is the third row: O, space, space.
  2. board[2][2] = "X" changes the last item in that row.
  3. Printing the row shows the whole list.

Answer: ['O', ' ', 'X']

Key idea

A 2D list is a list of lists that stores a table. Use name[row][column], with both indexes starting at 0. Nested loops visit every item.

Key words
AND
A Boolean operator that gives True (1) only when both inputs are True.
List
A data structure that stores many items under one name, in order, such as scores = [4, 7, 2].
Output
Information sent out from a computer, for example to a screen, speaker or printer.

All KS3 Computing key terms and definitions →

Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. grid is a 2D list with 5 rows, and each row has 6 items. How many items does it hold in total?

    Show the answer

    Answer: 30

    5 × 6 = 30.

  2. What is the FIRST number printed?
    scores = [[5, 8, 6],
    [9, 7, 10],
    [4, 6, 7]]
    for row in scores:
    total = 0
    for s in row:
    total = total + s
    print(total)

    Show the answer

    Answer: 19

    The first row totals 5 + 8 + 6 = 17.

Check you have got it

Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

Related lessons