🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Type Hints and Dataclasses: all 10 questions

Quiz: Type Hints and Dataclasses · Question 6 of 10

How do you give each dataclass object its own new empty list?

How do you give each dataclass object its own new empty list?

  1. A.items: list = []
  2. B.items: list = list
  3. C.items: list = field(default_factory=list)
  4. D.items: list = None, then never check it
Answer & explanation

Correct answer: items: list = field(default_factory=list)

default_factory calls list() separately for each object.

Can you get the rest right without peeking?

Take the timed Quiz: Type Hints and Dataclasses quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →