Q32: What benefits does the @dataclass decorator offer?

Introduced in Python 3.7, @dataclass generates boilerplate special methods (__init__(), __repr__(), __eq__(), __hash__()) automatically based on type annotations. Passing frozen=True enforces immutability.

Key Takeaways
  • Auto-generates __init__, __repr__, and __eq__ methods based on type hints.
  • frozen=True produces immutable, hashable instances.
Knowledge Check

How do you make a @dataclass instance immutable and hashable?