GCSE Computer Science (OCR)

Topic Summaries

ALGORITHMS AND PROGRAMMING: Programming techniques

Arrays (lists)

  • 1D arrays: store one list of items (e.g. names, scores)

# 1D array

names = [“Kai”, “Toby”, “Adika”]

print (names[1]) # Kai

  • 2D arrays: are arrays within arrays – like a table (rows and columns). 2D arrays are useful for emulating database tables (rows = records, columns = fields). Remember that the first row and column will be indexed as 0.

# 2D array

students = [

[“Kai”, 16, “A”]

[“Toby”, 17, “C”]

[“Adika”, 16, “B”]

]

print (students[0][2]) # A

Unlock Arrays (lists)

Sign up to unlock the rest of this topic — plus every other topic, video, flashcard set and eBook guide in your SnapRevise Digital subscription.

Cancel anytime — instant access the moment you sign up.