This is my script:
import math
class Vector:
def __init__(self, x=0.0, y=0.0):
self.x = x
self.y = y
def ___str___(self):
return "{0}, {1}".format(self.x, self.y)
@classmethod
def vectorPoints(cls, p1, p2):
a = p2[0] - p1[0]
b = p2[1] - p1[1]
return Vector(a, b)
A = (1,5)
B = (2,7)
vectAB = Vector.vectorPoints(A, B)
print(vectAB)
vect = Vector(1, 0)
print(vect)
When I run this script I get:
<__main__.Vector object at 0x00FD5ED0>
<__main__.Vector object at 0x00FD5FF0>
Apparently the __str__ method isn't returning anything.
The method name should be __str__ (2 underscores surrounding), not ___str___ (3 underscores surrounding).
You are using three underscores (_) instead of the normal two.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With