🎙 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 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))
  1. A.P(x=3, y=0)
  2. B.P(3)
  3. C.<P object>
  4. 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 →