Python · Lesson 12.6 · Pro

dataclasses

Write simple data-holding classes in a few lines, with printing and comparing built in.

In this lesson

  1. @dataclass writes __init__ for you
  2. Defaults and methods
  3. Lists need field(default_factory=...)
  4. Sortable and frozen