Questions in notes
import mathclass Point: def __init__(self, x=0.0, y=0.0): self.__x = x self.__y = y def getx(self): return self.__x def gety(self): return self.__y def distance_from_xy(self, x, y): return math.hypot(abs(self.__x - x), abs(self.__y - y))# In general, in brackets x,y Not all of them need to be defined first, for example self.__x and self.__y? Why? there self.__x Continue to use __init__ Inside def distance_from_point(self, point): return self.distance_from_xy(point.getx(), point.gety())""" I'm a little confused here , Do you want to write an expression first self.__point=point stay return Before ? And a little bit more , May I use self.getx() and self.gety() Instead of point.getx() and point.gety()? """ point1 = Point(0, 0)point2 = Point(1, 1)print(point1.distance_from_point(point2))print(point2.distance_from_xy(2, 0))
Finally, all double underlined variables __, I know it is private It means , If you don't use it, you can wow