Halo
发布于 2024-10-29 / 44 阅读 / 0 评论 / 0 点赞

类继承

class a:
  def __init__(self, name):
    self.name=name

class b:
  def __init__(self, p1, p2):
    self.p1=p1
    self.p2=p2

class c(a,b):
  def __init__(self):
    a.__init__(self, 'abc')
    b.__init__(self, p1=1, p2=2)

instance =c()
print(instance.name)
print(instance.p1)
print(instance.p2)

评论