标签:sub 方式 nbsp 多重继承 bsp class get init python
#方式一 class A(): def __init__(self, name): self.name = name print("a class ...") class B(): def __init__(self, age): self.age = age print("b class...") class Sub(A, B): def __init__(self, name, age, phone): A.__init__(self, name) B.__init__(self, age) self.phone = phone print("sub class...") def get_all_info(self): print(self.name, self.age, self.phone) if __name__ == '__main__': s = Sub("toby", 25, 110) s.get_all_info() #方式二 class A(): def __init__(self, name): self.name = name print("a class ...") class B(A): def __init__(self, name, age): super(B, self).__init__(name) self.age = age print("b class...") class Sub(B): def __init__(self, name, age, phone): super(Sub, self).__init__(name, age) self.phone = phone print("sub class...") def get_all_info(self): print(self.name, self.age, self.phone) if __name__ == '__main__': s = Sub("toby", 25, 110) s.get_all_info()标签:sub 方式 nbsp 多重继承 bsp class get init python
原文地址:http://blog.51cto.com/freshair/2058629