Python·100 questions

What is a dataclass and why is it needed?

Answer
dataclass reduces boilerplate for data classes.
@dataclass automatically creates __init__/__repr__/__eq__.
You can set frozen=True (immutability).
default_factory for lists/dicts.
Useful for DTOs/models.
Was this answer helpful?

More questions in this topic

Related questions from other topics