Python Point 类:计算两点间距离
以下是 Python 实现:
class Point: def init(self, x, y): self.x = x self.y = y
def distance(self, x2, y2):
return ((self.x - x2) ** 2 + (self.y - y2) ** 2) ** 0.5
测试
p = Point(0, 0) print(p.distance(3, 4)) # 输出 5.0
原文地址: https://www.cveoy.top/t/topic/ohli 著作权归作者所有。请勿转载和采集!