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)- A. False False
- B. True True
- C. False True
- 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
- What is printed? python x, y = "hello" print(x, y)
- What is printed? python print([x for x in range(20) if x % 2 == 0 if x % 3 == 0])
- What is printed? python print([x if x % 2 == 0 else -x for x in range(5)])
- What is printed? python words = ["banana", "kiwi", "apple", "fig"] print(sorted(words, key=len)) print(sorted(words, key=lambda w: w[-1]))
- What is printed? python s = "Hello World" print(s.swapcase()) print(s.title()) print(" a b ".split())
- What is printed? python print("a-b--c".split("-")) print("a-b--c".split("-", 1))