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

爱⌒轻易说出口 提交于 2019-12-03 17:26:54
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

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!