Dataclasses and Typed Structures

Dataclasses and Typed Structures#

Learning Objectives#

After working through this topic, you should be able to:

  • Create typed dataclasses with field annotations

  • Use frozen=True for immutable dataclasses

  • Handle mutable defaults correctly with field(default_factory=…)

  • Choose between dataclasses, NamedTuples, and TypedDicts

  • Add validation and computed fields with post_init

Materials#

Download the slides.

Quiz#