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