Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Arrays and Records

2D arrays

All topicsPractise exam questions
Knowledge organiser

Arrays and Records

301.17b

Table structure rows/cols.

What you need to know

A 2D array is a list of lists, representing rows and columns like a table. Access elements with two indices: grid[row][col].

Key points

  • A list of lists: grid = [[1,2],[3,4],[5,6]]
  • grid[0] is the first row
  • grid[0][1] is row 0, column 1
  • Use nested for loops to process all elements

Code examples

2D array
python
grid = [
    [1, 2, 3],
    [4, 5, 6]
]
print(grid[0][2])  # 3 (row 0, col 2)

for row in grid:
    for item in row:
        print(item, end=" ")
    print()