首页 > 技术文章 > Python类的继承

randomlee 2018-05-09 12:23 原文

python2里面的经典类的继承是深度优先

python2里面的新式类的继承是广度优先

python3里面的经典类和新式类的继承是广度优先

 

Python 2.x中默认都是经典类,只有显式继承了object才是新式类

Python 3.x中默认都是新式类,不必显式的继承object

 

class Teacher(SchoolMember,Person):
    def __init__(self,name,age,sex,salary,course):
     #SchoolMember.__init__(self,name,age,sex)
     #Person.__init__(self,dress)
     #不推荐以上继承方式,手动改变了python继承的顺序,会产生BUG
        super(Teacher,self).__init__(name,age,sex)
        self.salary = salary
        self.course = course

 

推荐阅读