Accessing record fields by index
Reads a field from a record stored as a tuple by its index position. Indexes start at 0, so student[0] is the first field. You must know which field sits at which index.
Understanding Accessing record fields by index in VCE Applied Computing U1O2
What it does: The code reads the field at index 3 (the fourth field). Nothing in the code names the field, so you have to know the mark sits at index 3. This tuple has an int ID at index 0, a string name at index 1, an int age at index 2 and a float mark at index 3, all in one record. Indexes start at 0. student[0] is 101, student[1] is "Mia", student[2] is 16 and student[3] is 87.5. The age 16 is the third field, so its index is 2. Index 3 is the score, 87.5. A record with 4 fields has indexes 0 to 3. Index 4 is out of range and causes an IndexError.
Common mistakes: Fields of a tuple record are read with square brackets, not round brackets. It should be name = student[1]. A comma is missing between the first two fields, so the record is not valid. It should be (7, "Liam", 16, 92.0).
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 8–88) and word search (Modules 8–124).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
student[1]Fill in the Blanks
Spot the Error
Student with a class code? Join your class →