python同时继承多个类且方法相同

class A(object):
    def getName(self):
        print("name is A")

class B(object):
    def getName(self):
        print("name is B")

class C(A, B):
    def __init__(self):
        print("class is C")
c = C()
c.getName()


class D(B, A):
    def __init__(self):
        print("class is D")
d = D()
d.getName()

执行结果为:

"D:\Program Files\python3.6.7\python.exe" D:/pythonWorkspace/untitled1019/test/test1.py
class is C
name is A
class is D
name is B

Process finished with exit code 0

 

posted on 2019-11-06 13:56  芦苇草鱼  阅读(3807)  评论(0编辑  收藏  举报