Track 11 · Lesson 11 of 12
Dataclasses
Write record-style classes in a few lines with @dataclass, including defaults, default factories, frozen and ordered instances and __post_init__ validation.
You will be able to
- Define a dataclass with typed fields and get __init__, __repr__ and __eq__ generated
- Give fields default values, using field(default_factory=list) for mutable ones
- Make instances immutable with frozen=True and sortable with order=True
- Validate and normalise fields in __post_init__
- Exclude fields from comparison or repr with field(compare=False, repr=False)
Included with a Formula Quest membership
It has 5 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.
View Formula Quest memberships
Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.