Junior — Middle
Have you used the dataclass decorator in your projects?
sobes.tech AI
Answer from AI
Yes, the @dataclass decorator in Python is used to automatically add standard methods to a class, such as __init__, __repr__, __eq__, and others, which significantly reduces boilerplate code.
Example of usage:
from dataclasses import dataclass
@dataclass
class Point:
x: int
y: int
p = Point(1, 2)
print(p) # Point(x=1, y=2)
This is convenient for classes that mainly store data, such as DTOs, configurations, or computation results.