#it's python 3.2.3
class point:
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, point):
self.x += point.x
self.y += point.y
return self
def __repr__(self):
return 'point(%s, %s)' % (self.x, self.y)
class Test:
def __init__(self):
self.test1 = [point(0, i) for i in range(-1, -5, -1)]
self.test2 = [point(i, 0) for i in range(-1, -5, -1)]
print('%s\n+\n%s\n=\n%s' % (self.test1[0], self.test2[0], self.test1[0] + self.test2[0]))
test = Test()
input()
The output of this program is
point(-1, -1)
+
point(-1, 0)
=
point(-1, -1)
But it should be
point(-1, -1)
+
point(-1, 0)
=
point(-2, -1)
But if I do
print(point(-1, -1) + point(-1, 0))
It works perfectly
I want to know why, and how to solve this problem
p.s. sorry if my english is bad :)