- import math
- #class Point
- class Point:
- def __init__(self, xValue, yValue):
- self.X = xValue
- self.Y = yValue
- #class Circle
- class Circle(Point):
- def __init__(self, xValue, yValue, rValue):
- Point.__init__(self, xValue, yValue)
- self.Radious = rValue
- def area(self):
- return math.pi * self.Radious ** 2
- #driver
- print("Point bases:", Point.__bases__)
- print("Circle bases:", Circle.__bases__)
- print("Circle is the subclass of Point:", issubclass(Circle, Point))
- print("Point is the subclass of Circle:", issubclass(Point, Circle))
- point = Point(3, 4)
- circle = Circle(4, 5, 2)
- print("point is an instace of Point:", isinstance(point, Point))
- print("circle is an instace of Point:", isinstance(circle, Point))
- print("point members:", point.__dict__)
- print("circle members:", circle.__dict__)
- print("the area if circle is:", circle.area())
python继承
最新推荐文章于 2024-08-15 01:55:01 发布