← VCE Applied Computing U1O2

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).

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 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.

Learning
Duo
student = (101, "Mia", 16, 87.5) Which index gives the name "Mia"?
student[1]student[2]
Matches
student = (101, "Ava", 15, 88.5) print(student["name"])
↓
A tuple record is read by index number, not by field name. Use student[1] to get the name.
Applying
Meanings
Term
student[1]
Meaning
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.
Practice
student = (101, "Ava", 88, True)
Testing
Gaps
print(student[]) # the ID
Check Answer
Spots
1student = (101, "Ava", 15, 88.5)
2name = student(1)

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

The 'Armadillo' badge — Shield Bearer, 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. student = (101, "Mia", 16, 87.5) Which index gives the name "Mia"?
A. student[1] ✓
B. student[2]
Indexes start at 0. student[0] is 101, student[1] is "Mia", student[2] is 16 and student[3] is 87.5.
2. student = (101, "Mia", 16, 87.5) What does student[0] return?
A. 101 (the ID) ✓
B. "Mia" (the name)
Index 0 is the first field. In this record the first field is the ID, so student[0] is 101.
3. Which statement about reading a tuple record is true?
A. You read a field by typing its field name, like student["name"]
B. You must know which index holds each field ✓
A tuple has no field names. You use index positions, so you must remember the order of the fields.
4. student = (101, "Mia", 16, 87.5) Which line prints the age?
A. print(student[3])
B. print(student[2]) ✓
The age 16 is the third field, so its index is 2. Index 3 is the score, 87.5.
5. student = (101, "Mia", 16, 87.5) What happens when you run print(student[4])?
A. An IndexError, because the last index is 3 ✓
B. It prints 87.5, the last field
A record with 4 fields has indexes 0 to 3. Index 4 is out of range and causes an IndexError.

Match the Pairs

student = (101, "Ava", 15, 88.5) print(student[1]) → Prints "Ava", the second field, because index 1 is the second position in the tuple record
student[0] → Reads the first field of the record, which is the ID in this record layout
Fields in a tuple record are read by index position, not by name, so you must remember the field order → mark = student[3]
One record can mix data types, so each index holds a different type: int, string, int, float → student = (101, "Ava", 15, 88.5)
student = (101, "Ava", 15, 88.5) print(student["name"]) → A tuple record is read by index number, not by field name. Use student[1] to get the name.
id = student[1] → The ID is the first field, so it sits at index 0, not 1. Indexes start at 0, so use student[0].

Key Term

student[1]
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.

Fill in the Blanks

1. student = (101, "Ava", 15, 88.5) print(student[0]) # the ID
Hint: Type the index position of the first field, the student ID
2. student = (101, "Ava", 15, 88.5) name = student[1]
Hint: Type the index of the field that holds the student's name
3. student = (7, "Liam", 16, 72.5) print(student[2])
Hint: Type the variable name that holds the tuple record
4. student = (101, "Ava", 15, 88.5) mark = student[3]
Hint: Type the index of the decimal number field, the last one in this record
5. ID, NAME, SCORE = 0, 1, 2 student = (5, "Zoe", 91.5) print(student[SCORE])
Hint: Type the constant that stores the index of the last field

Spot the Error

Question 1
A student = (101, "Ava", 15, 88.5)
B name = student(1)
C print(name)
Line B — Fields of a tuple record are read with square brackets, not round brackets. It should be name = student[1].
Question 2
A student = (7 "Liam", 16, 92.0)
B print(student[0])
C print(student[1])
Line A — A comma is missing between the first two fields, so the record is not valid. It should be (7, "Liam", 16, 92.0).
Question 3
A student = (12, "Zoe", 14, 77.5)
B student_id = student[0]
C age = student[3]
D print(student_id, age)
Line C — Index 3 holds the mark (77.5), not the age. Age is the third field, which sits at index 2, so it should be student[2].
Question 4
A student = (5, "Noah", 15, 63.0)
B print(student["name"])
C print(student[3])
Line B — A tuple record is read by index position, not by field name. The name is the second field, so use student[1].
Question 5
A student = ("Mia", 9, 17, 95.5)
B print("ID:", student[0])
C print("Name:", student[1])
Line A — The fields are in the wrong order. The ID must be first so that student[0] is the ID and student[1] is the name. It should be (9, "Mia", 17, 95.5).

Student with a class code? Join your class →