python继承

  1. import math  
  2. #class Point  
  3.   
  4. class Point:  
  5.     def __init__(self, xValue, yValue):  
  6.         self.X = xValue  
  7.         self.Y = yValue  
  8.   
  9.   
  10. #class Circle  
  11. class Circle(Point):  
  12.     def __init__(self, xValue, yValue, rValue):  
  13.         Point.__init__(self, xValue, yValue)  
  14.         self.Radious = rValue  
  15.   
  16.     def area(self):  
  17.         return math.pi * self.Radious ** 2   
  18.   
  19.   
  20.   
  21. #driver  
  22. print("Point bases:", Point.__bases__)  
  23. print("Circle bases:", Circle.__bases__)  
  24.   
  25. print("Circle is the subclass of Point:", issubclass(Circle, Point))  
  26. print("Point is the subclass of Circle:", issubclass(Point, Circle))  
  27.   
  28. point = Point(34)  
  29. circle = Circle(452)  
  30.   
  31. print("point is an instace of Point:", isinstance(point, Point))  
  32. print("circle is an instace of Point:", isinstance(circle, Point))  
  33.   
  34. print("point members:", point.__dict__)  
  35. print("circle members:", circle.__dict__)  
  36.   
  37. print("the area if circle is:", circle.area())  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值