Skip to content
UPEEC

Dataclasses

@dataclass writes __init__, __repr__ and __eq__ for classes that mainly hold data.

Easy
Comments 0
from dataclasses import dataclass, field
@dataclass(frozen=True)
class Reading:
    sensor: str
    value: float
    tags: list[str] = field(default_factory=list)

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.