• Python多重继承问题,新手求解答
  • python

class Point(object):
   def __init__(self,x,y):
       self.x = x
       self.y = y

   def string(self):
       print("X:{0},Y:{1}".format(self.x,self.y))

class Circle(Point):
   def __init__(self,x,y,radius):
       super(Circle, self).__init__(x,y)
       self.radius = radius

   def string(self):
       print("该图形初始化点为:X:{0},Y:{1};半径为:{2}".format(self.x,self.y,self.radius))

class Size(object):
   def __init__(self,width,height):
       self.width = width
       self.height = height

   def string(self):
       print("Width:{0},Height:{1}".format(self.width,self.height))

class Rectangle(Point,Size):
   def __init__(self,x,y,width,height):
       super(Rectangle,self).__init__(x,y,width,height)

   def string(self):
       print("该图形初始化点为:X:{0},Y:{1};长宽分别为:Width:{2},Height:{3}".format(self.x,self.y,self.width,self.height))



if __name__ =='__main__':
   c = Circle(5,5,8)
   c.string()
   r1 = Rectangle(15,15,15,15)
   r1.string()
   r2 = Rectangle(40,30,11,14)
   r2.string()

当执行时出现报错
提示:Traceback (most recent call last):
File "D:/py/class/2-6.py", line 39, in 
r2 = Rectangle(40,30,11,14)
File "D:/py/class/2-6.py", line 28, in init
super(Rectangle,self).__init__(x,y,width,height)
TypeError: init() takes 3 positional arguments but 5 were given


  • 就几件    2020-03-09 13:36:00
  • 阅读 628    收藏 0    回答 1
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信