1、python的多继承中,如果父类拥有相同的方法和属性,以优先继承为主
代码如下:
```
class A(object):
text ='hello a'
def print_hello(self):
print('this is print_hello of A class')
print(self.text)
class B(object):
text ='hello b'
def print_hello(self):
print('this is print_hello of B class')
print(self.text)
class C(B, A):
pass
def inherit_test():
c = C()
c.print_hello()
if __name__ =='__main__':
inherit_test()
```
运行结果如下:
```
this is print_hello of B class
hello b
```