class A (object):
def __init__(self):
self.number = 1
def print_info(self):
print ('这是父类A')
class B (object):
def __init__(self):
self.number = 2
def print_info(self):
print ('这是父类B')
class C (A, B):
def __init__(self):
self.number = 3
def print_info(self):
print ('这是子类C')
def print_info_from_A(self):
A.__init__ (self)
A.print_info (self)
def print_info_from_B(self):
B.__init__ (self)
B.print_info (self)
D = C ()
D.print_info ()
D.print_info_from_B ()
D.print_info_from_A ()
python面对对象编程——继承
最新推荐文章于 2024-08-29 19:30:55 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)