0

Need help

class Vector2D: def __init__(self, x, y): self.x = x self.y = y def __add__(self, other): return Vector2D(self.x + other.x, self.y + other.y) first = Vector2D(5, 7) second = Vector2D(3, 9) result = first + second print(result.x) print(result.y) here what confuse me is how come the value of-other.x is 3. and the the value of other.y is 9.

16th Oct 2017, 7:33 AM
stephen haokip
stephen haokip - avatar
1 Resposta
+ 1
because the line result = first + second it's the same with result = first.__add__(second) in python self parameter is the calling object here is first, so other parameter is second in this case
16th Oct 2017, 7:43 AM
bogdan
bogdan - avatar