类和对象:继承
来源:互联网 发布:剑桥大学生活费 知乎 编辑:程序博客网 时间:2024/05/17 08:11
读书笔记:
我的代码:
# -*- coding: gbk -*-import mathclass Point(): def __init__(self,x,y): self.x = x self.y = yclass Line(): def __init__(self,p1,p2): self.p1 = p1 self.p2 = p2 def getLength(self): return math.sqrt((self.p1.x-self.p2.x)**2+\ (self.p1.y-self.p2.y)**2)p1 = Point(1,1)p2 = Point(7,9)line = Line(p1,p2)print("线段的长度是:%.2f"%line.getLength())
阅读全文