PythiloLesson 3 of 9 · progress kept in this browser

Dataclasses

@dataclass writes __init__, __repr__ and __eq__ from a list of annotated fields. Use it for objects that mainly hold data.

from dataclasses import dataclass, field

@dataclass
class Order:
    item: str
    qty: int = 1
    notes: list[str] = field(
        default_factory=list)

Each Order gets its own notes list. A plain notes: list = [] is rejected with an error, because all instances would share one list.

Your task

Write a dataclass Task with title: str, priority: int = 0 and tags: list[str] defaulting to a new empty list, raising ValueError for an empty title. Write a frozen dataclass Point with x: int and y: int.