OCR · GCSE · Computer Science
Course version: J277 · Version from Sept 2022
Additional programming techniques: The use of records to store data
A record groups related data items about one entity into a single structure.
Checked against the OCR J277 specification on .
- Point 3 of 7
- 4 key terms
Study notes
From the checked teaching notes for this specification point.
The idea
A record groups related data items about one entity into a single structure. Each field has a name and a data type, such as a student record with fields name (string), age (integer) and average (real). In Python you can implement a record as a dictionary with named keys, for example student = {'name':'Ama','age':14,'average':67.5}. Access a field with student['name'] and update it with student['age'] = 15. Records make programs clearer because fields are referenced by name rather than by position, and they keep related values together. You can store many records in a list or file, then loop through them to search, calculate or display. When reading records from a file, split each line into fields and convert numeric fields before use.
What earns the marks
- A record is a data structure that stores related fields about one entity, with each field having a name and a data type.
- Fields are accessed by name, which improves readability and reduces errors compared with remembering positional indexes.
- Records can be implemented in Python using dictionaries with string keys, or as objects of a class with attributes.
- Multiple records can be held in a list, allowing iteration to search, sort, total or display data for many entities.
- When records are stored in a text file, each line can represent one record and delimiters such as commas separate fields; parsing and type conversion are needed after reading.
- Updating a record means assigning a new value to a named field, for example student['age'] = 15, without affecting other fields.
Common mistakes and how to put them right
Confusing a record with an array, then accessing fields by numeric index.
Put it right: Use named keys or attributes so the meaning of each field is clear.
Storing numeric data as strings and then attempting arithmetic.
Put it right: Convert fields with int() or float() after reading or input.
Forgetting that a dictionary key must match exactly, including case.
Put it right: Use consistent key names and check spelling.
Treating a list of records as a single record.
Put it right: Loop over the list and access fields on each record in turn.
Exam tips
- Define the fields and their data types before writing code, so your record structure is complete and consistent.
- Use meaningful field names such as 'price' or 'quantity' rather than vague names like 'x' or 'data'.
- When reading records from a file, show how you split each line and convert numeric fields before calculation.
- If asked to update a record, show the assignment to the named field and explain that other fields remain unchanged.
Try the lesson
The start of the Additional programming techniques: The use of records to store data lesson, made from checked teaching notes for this specification point.
Have a go first
What is a record used for in a program?
Listen
A record groups related data items about one entity into a single structure. Each field has a name and a data type, such as a student record with fields name (string), age (integer) and average (real). In Python you can implement a record as a dictionary with named keys, for example student = {'name':'Ama','age':14,'average':67.5}. Access a field with student['name'] and update it with student['age'] = 15. Records make programs clearer because fields are referenced by name rather than by position, and they keep related values together. You can store many records in a list or file, then loop through them to search, calculate or display. When reading records from a file, split each line into fields and convert numeric fields before use. A strong answer earns marks for these points. A record is a data structure that stores related fields about one entity, with each field having a name and a data type. Fields are accessed by name, which improves readability and reduces errors compared with remembering positional indexes. Records can be implemented in Python using dictionaries with string keys, or as objects of a class with attributes. Multiple records can be held in a list, allowing iteration to search, sort, total or display data for many entities. A common slip: Confusing a record with an array, then accessing fields by numeric index. Instead, use named keys or attributes so the meaning of each field is clear. Exam tip: Define the fields and their data types before writing code, so your record structure is complete and consistent.
Key words
Say what each word means before you turn the card.
Record
Try answering aloud or in your head before turning the card.
Named fields and data types
Try answering aloud or in your head before turning the card.
Accessing and updating fields by name
Try answering aloud or in your head before turning the card.
Storing multiple records in a collection
Try answering aloud or in your head before turning the card.
See every definition
- Record
- A data structure that stores related fields about one entity, with each field having a name and a data type.
- Named fields and data types
- Each field in a record has a name and a data type, such as name (string), age (integer) and average (real).
- Accessing and updating fields by name
- A field is accessed by name, such as student['name'], and updated by assigning a new value to that named field.
- Storing multiple records in a collection
- Many records can be held in a list or file, then looped through to search, calculate or display.
There is more to this lesson
The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge
Test your understanding of Additional programming techniques: The use of records to store data
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge