多重继承

简介

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# coding:utf-8

class Tool():
def work(self):
return 'tool work'
def car(self):
return 'car will run'

class Food():
def work(self):
return 'food work'
def cake(self):
return 'i like cake'

class Person(Tool,Food): # 形参从左到右继承。
pass

p = Person()
p_car = p.car()
p_cake = p.cake()
p_work = p.work()
print(p_car,p_cake,': ',p_work)
print(Person.__mro__) # 查看对象的继承链。