Menu

Records

Why records are used

A record stores all the data about one item — one member of a club, one player, one order — as a single unit. Each piece of data inside it is a field, and the fields can hold different types of data: text for a name, a whole number for an age, a Boolean (shown here as Yes or No) for whether a fee is paid. Because the fields are kept together, the record can be stored, searched, updated and output as one thing, instead of as separate pieces that could get out of step.

Here each row is one member's record. All rows use the same four columns, always in this sequence: Member ID, Name, Age, Fee paid?

Member IDNameAgeFee paid?
M-104Priya14Yes
M-207Owen15No
M-315Aisha13Yes

This is how data is organised in a database table, and in a file where each line holds one record. Rows are records and columns are fields, so a record you build in a program lines up with what a table or file already stores.

Keeping the fields together pays off when you use the data. Change M-207's fee status and Owen's name and age are already in the same row — no need to update three separate lists and hope they stay in step. Update one field and the rest of the record stays with it.

Because each row follows the same fixed layout, one loop can process every row in the same way: the name always sits at index 1, the age at index 2, so the same code works for every row. The loop works for three records or three hundred without extra code.

# fixed positions: name is record[1], age is record[2]
members = [
    ["M-104", "Priya", "14", "Yes"],
    ["M-207", "Owen", "15", "No"],
    ["M-315", "Aisha", "13", "Yes"]
]

for record in members:
    print(record[1] + " is " + record[2] + " years old")

Output:

Priya is 14 years old
Owen is 15 years old
Aisha is 13 years old

If one row had its fields in a different order, that same index would pick up a different field and the results would be wrong — which is why the shared layout matters.

Practise this