demos/point.py

15 lines
426 B
Python

class Point:
def __init__(self, x, y): # Dunder init "Double underscore init"
self.x = x
self.y = y
def __repr__(self):
return f"Point(x={self.x}, y={self.y})"
def dist_from_origin(self):
return (self.x**2 + self.y**2) ** 0.5
def dist(self, other):
"""Compute distance between two points."""
return ((self.x - other.x) ** 2 + (self.y - other.y) ** 2) ** 0.5