What is the output of the following Python code snippet?
from dataclasses import dataclass
@dataclass
class P:
x: int
y: int
print(P(1, 2))
-
A
<P object>
-
B
(1, 2)
-
C
Error
-
D
P(x=1, y=2)
Correct answer
Correct answer
D. P(x=1, y=2)
5 views
Explanation
A dataclass generates a readable __repr__.
Doubts & discussion
Not sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ