Guided pathThis is part of Go from writing Python to engineering itBack to the path

Records: class vs dataclass vs namedtuple

P28.data-modelling.01 · Audience: guest, it-ml, language-pro

Real LLM grading for this pageLLM grading (this page):

Welcome to Objects & Data Modelling — the first pillar of the Advanced Python discipline. Python gives you several ways to model a bundle of data, and picking the right one is a daily design decision. This ladder starts there: a plain class, a dataclass, and a namedtuple, and when each earns its keep.

Each rung below is a three-panel workspace: instructions on the left, a code editor in the middle, and output + test results on the right.

  • Run checks the visible tests you can read in the instructions.
  • Submit grades your code against hidden tests (extra edge cases), so you can't pass by hard-coding the shown answers.
  • The reference solution unlocks once you pass.

The code runs entirely in your browser (Pyodide — Python compiled to WebAssembly); nothing leaves your machine.

Ask the mentor about this module

Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.

Images, PDF or text. Kept on this device only.
Keeping your files on this device

Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.

Ctrl/Cmd + Enter to send
Rung 1 — reach for a dataclass

Loading exercise…

Rung 2 — rebuild the record from scratch

Loading exercise…

Interview rung — class vs dataclass vs namedtuple (free-form)

Loading exercise…

My notes on this module

Loading your notes...

Records: class vs dataclass vs namedtuple — TransformerLab