I am new to Python and I have just created a class as part of the online course I am taking.
from math import sqrt
class Line:
def __init__(self,coor1,coor2):
self.coor1=coor1 #tuple (x1,y1)
self.coor2=coor2 #tuple (x2,y2)
def distance(self):
return sqrt((self.coor2[0]-self.coor1[0])**2+(self.coor2[1]-self.coor1[1])**2)
def slope(self):
return (self.coor2[1]-self.coor1[1])/(self.coor2[0]-self.coor1[0])
This is a class for Line
and helps me find the distance between two coordinates. I am wondering, since a coordinate needs to be a tuple, how does Python know this? Why don't I need to define this in the def __init__
?