1. Home
  2. Data Science
  3. Python
  4. What does the @dataclass decorator generate automatically…

Added 2 Nov 2026

What does the @dataclass decorator generate automatically for a class?

  1. __init__, __repr__ and __eq__ methods Correct answer
  2. A database table for the class
  3. Getter and setter for each field
  4. Type checking at runtime for fields

Correct answer

A. __init__, __repr__ and __eq__ methods

17 views

MCQSEXAM

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

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs