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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM