← 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?
- A.items: list = []
- B.items: list = list
- C.items: list = field(default_factory=list)
- 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 →