一.单继承:子类只继承一个父类
#父类
class Animal(object):
def eat(self):
print('它喜欢吃东西')
def sleep(self):
print('它喜欢睡觉')
#子类
class Cat(Animal):
pass
a=Cat() #实例化对象
a.eat()
a.sleep()
二.多继承
#父类Master
class Master():
def __init__(self):
# 属性
self.kongfu='古法煎饼果子配方'
def make_cake(self):
print('按照%s制作煎饼果子' %(self.kongfu))
#父类 School
class School():
def __init__(self):
self.kongfu='现代煎饼果子配方'
def make_cake(self):
print('按照%s只做煎饼果子' %(self.kongfu))
#子类Prentice继承父类Master和School
class Prentice(Master,School):
#就近原则
pass
#实例化对象
damao=Prentice()
damao.make_cake()
#查看调用顺序
print(Prentice.__mro__)
按照古法煎饼果子配方制作煎饼果子
(<class '__main__.Prentice'>, <class '__main__.Master'>, <clas