Question OOP-POLY-0065
HardWhat is the output of this code?
class V:
def __init__(self, x): self.x = x
def __add__(self, o): return V(self.x + (o.x if isinstance(o, V) else o))
def __radd__(self, o): return self + o
def __repr__(self): return f"V({self.x})"
print(sum([V(1), V(2), V(3)]))
- A.
6
- B.
V(3)
- C.
Sign up free to see the answer and a step-by-step explanation.