关于 python 新式类和旧式类继承顺序的验证

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于 python 新式类和旧式类继承顺序的验证相关的知识,希望对你有一定的参考价值。

参考:http://www.cnblogs.com/blackmatrix/p/5630515.html

官方:https://docs.python.org/2/tutorial/classes.html 

 

 

关于多继承问题

 

Python supports a limited form of multiple inheritance as well. A class definition with multiple base classes looks like this:

For old-style classes, the only rule is depth-first, left-to-right. Thus, if an attribute is not found in DerivedClassName, it is searched in Base1, then (recursively) in the base classes of Base1, and only if it is not found there, it is searched in Base2, and so on.

(To some people breadth first — searching Base2 and Base3 before the base classes of Base1 — looks more natural. However, this would require you to know whether a particular attribute of Base1 is actually defined in Base1 or in one of its base classes before you can figure out the consequences of a name conflict with an attribute of Base2. The depth-first rule makes no differences between direct and inherited attributes of Base1.)

For new-style classes, the method resolution order changes dynamically to support cooperative calls to super(). This approach is known in some other multiple-inheritance languages as call-next-method and is more powerful than the super call found in single-inheritance languages.

 

 

试验部分

 

请看这里

 

 

以上.

以上是关于关于 python 新式类和旧式类继承顺序的验证的主要内容,如果未能解决你的问题,请参考以下文章

旧式类、新式类和元类

面向对象新式类和旧式类的区别

python 之简单浅谈新式类和旧式类(或称经典类)

python中新式类和经典类

类和对象

多继承