← Quiz: Type Hints and Dataclasses: all 10 questions
Quiz: Type Hints and Dataclasses · Question 5 of 10
What does this print? (code)
What does this print?
from dataclasses import dataclass
@dataclass
class P:
x: int
y: int = 0
print(P(3))
- A.P(x=3, y=0)
- B.P(3)
- C.<P object>
- D.An error
Answer & explanation
Correct answer: P(x=3, y=0)
The generated repr shows every field with its value.
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 →