继承中>>>广度优先和深度优先的选择策略
作者:互联网
新式类和经典类的区别在哪里???
就是在多继承上的顺序问题
py2经典类是按深度优先来继承得,新式类是按广度优先来继承的
py3经典类和新式类都是统一按广度优先来继承的
class People(object): # 新式类 经典类和新式类在多继承上的方式有所不同
def __init__(self, name, age):
self.name = name
self.age = age
self.friends = []
print("---doens't run ")
def eat(self):
print("%s is eating..." % self.name)
def sleep(self):
print("%s is sleeping..." % self.name)
def talk(self):
print("%s is talking..." % self.name)
class Relation(object):
def __init__(self, n1, n2):
print("init in relation")
def make_friends(self, obj):
print("%s is making friends with %s" % (self.name, obj.name))
self.friends.append(obj)
class Man(People, Relation): # 如果两个都有够着函数的话,谁在前面就执行谁的实例化,从左到右。如果其中一个没有,就执行另外一个的构造函数
标签:__,优先,name,self,深度,print,广度,friends,def 来源: https://blog.51cto.com/u_14303514/2930446