Glossary · Phase 7 · Software engineering
Dataclass
A Python class declared by listing its typed fields; Python writes the setup code for you.
A dict like
{"sku": "TENT-2", "qty": 2}is a blank sheet of paper: easy to write on, and nothing stops a typo likeorder["qyt"]. A dataclass is a printed form. It declares the fields once, with types, and Python writes the boring parts of the class for you:__init__, a readablerepr, and==.
Try it now
One small class gives you named fields, a readable print and a default, with no extra code.
Learn it properly
Types and data modeling · Type hints, dataclasses and checking data at the edges of a program. About 35 minutes.
Other terms from the same lesson
- enum: A fixed set of allowed values, such as an order status of pending, paid or shipped.
- type hint: A note in the code saying what type a value should be, like price: float. Tools check hints; Python doesn't enforce them.
Never trained an AI?
Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.