ProgrammingHardAccenture pattern

What is printed?

What is printed?
from dataclasses import dataclass
@dataclass
class Point:
    x: int
    y: int = 0
p1 = Point(1, 2)
p2 = Point(1, 2)
print(p1 == p2, p1 is p2)
  1. A. False False
  2. B. True True
  3. C. False True
  4. D. True False

Correct answer: D. True False

@dataclass auto-generates __eq__ that compares fields, so p1 == p2 is True (both have x=1, y=2). It does NOT make them the same object, so p1 is p2 is False.

More Python Programming questions

Exams that ask this topic