class Vector2(object):
def __init__(self, x= 0.0, y = 0.0):
self.x = x
self.y = y
def __str__(self):
return "(%s, %s)" % (self.x, self.y)
@classmethod
def from_points(cls, P1, P2):
return cls( P2[0] - P1[0], P2[1] - P1[1] )
A = (10.0, 20.0)
B = (30.0, 35.0)
AB = Vector2.from_points(A, B)
print AB
I'M having trouble understanding some of this code. First of all, is the classmethod the same thing as a static method? At what point in this program is it actually called. I also thought I remembered there was another way to right class methods.
What is the parameter cls?
Last but not least, what produces the final output? Is it the line print AB or the __str__ method?
Thanks for any and all replies.