What does the @dataclass decorator generate automatically for a class?
-
A
__init__, __repr__ and __eq__ methods
Correct answer
-
B
A database table for the class
-
C
Getter and setter for each field
-
D
Type checking at runtime for fields
Correct answer
A. __init__, __repr__ and __eq__ methods
17 views
Explanation
dataclasses (Python 3.7+) cut boilerplate for classes that mainly hold data. Type hints declare the fields but are not enforced at runtime.
Reference
Asked in: NTS, Python Developer Interviews
Doubts & discussion
Not sure why the answer is A? Ask here and get an explanation.
Ask a doubt about this MCQ