<tfoot id='l1W1V'></tfoot>
        <bdo id='l1W1V'></bdo><ul id='l1W1V'></ul>

    1. <legend id='l1W1V'><style id='l1W1V'><dir id='l1W1V'><q id='l1W1V'></q></dir></style></legend>

      <small id='l1W1V'></small><noframes id='l1W1V'>

    2. <i id='l1W1V'><tr id='l1W1V'><dt id='l1W1V'><q id='l1W1V'><span id='l1W1V'><b id='l1W1V'><form id='l1W1V'><ins id='l1W1V'></ins><ul id='l1W1V'></ul><sub id='l1W1V'></sub></form><legend id='l1W1V'></legend><bdo id='l1W1V'><pre id='l1W1V'><center id='l1W1V'></center></pre></bdo></b><th id='l1W1V'></th></span></q></dt></tr></i><div id='l1W1V'><tfoot id='l1W1V'></tfoot><dl id='l1W1V'><fieldset id='l1W1V'></fieldset></dl></div>

      Python中的旧样式类和新样式类有什么区别?

      时间:2024-04-22
        <tbody id='zuUGG'></tbody>
        <bdo id='zuUGG'></bdo><ul id='zuUGG'></ul>

          <legend id='zuUGG'><style id='zuUGG'><dir id='zuUGG'><q id='zuUGG'></q></dir></style></legend>
        1. <small id='zuUGG'></small><noframes id='zuUGG'>

            <i id='zuUGG'><tr id='zuUGG'><dt id='zuUGG'><q id='zuUGG'><span id='zuUGG'><b id='zuUGG'><form id='zuUGG'><ins id='zuUGG'></ins><ul id='zuUGG'></ul><sub id='zuUGG'></sub></form><legend id='zuUGG'></legend><bdo id='zuUGG'><pre id='zuUGG'><center id='zuUGG'></center></pre></bdo></b><th id='zuUGG'></th></span></q></dt></tr></i><div id='zuUGG'><tfoot id='zuUGG'></tfoot><dl id='zuUGG'><fieldset id='zuUGG'></fieldset></dl></div>

                <tfoot id='zuUGG'></tfoot>
              1. 本文介绍了Python中的旧样式类和新样式类有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                What is the difference between old style and new style classes in Python? When should I use one or the other?

                解决方案

                From New-style and classic classes:

                Up to Python 2.1, old-style classes were the only flavour available to the user.

                The concept of (old-style) class is unrelated to the concept of type: if x is an instance of an old-style class, then x.__class__ designates the class of x, but type(x) is always <type 'instance'>.

                This reflects the fact that all old-style instances, independently of their class, are implemented with a single built-in type, called instance.

                New-style classes were introduced in Python 2.2 to unify the concepts of class and type. A new-style class is simply a user-defined type, no more, no less.

                If x is an instance of a new-style class, then type(x) is typically the same as x.__class__ (although this is not guaranteed – a new-style class instance is permitted to override the value returned for x.__class__).

                The major motivation for introducing new-style classes is to provide a unified object model with a full meta-model.

                It also has a number of immediate benefits, like the ability to subclass most built-in types, or the introduction of "descriptors", which enable computed properties.

                For compatibility reasons, classes are still old-style by default.

                New-style classes are created by specifying another new-style class (i.e. a type) as a parent class, or the "top-level type" object if no other parent is needed.

                The behaviour of new-style classes differs from that of old-style classes in a number of important details in addition to what type returns.

                Some of these changes are fundamental to the new object model, like the way special methods are invoked. Others are "fixes" that could not be implemented before for compatibility concerns, like the method resolution order in case of multiple inheritance.

                Python 3 only has new-style classes.

                No matter if you subclass from object or not, classes are new-style in Python 3.

                这篇关于Python中的旧样式类和新样式类有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何打破多个循环? 下一篇:@property 装饰器在 Python 中是如何工作的?

                相关文章

                <small id='fVJvZ'></small><noframes id='fVJvZ'>

                • <bdo id='fVJvZ'></bdo><ul id='fVJvZ'></ul>

                1. <legend id='fVJvZ'><style id='fVJvZ'><dir id='fVJvZ'><q id='fVJvZ'></q></dir></style></legend>
                2. <i id='fVJvZ'><tr id='fVJvZ'><dt id='fVJvZ'><q id='fVJvZ'><span id='fVJvZ'><b id='fVJvZ'><form id='fVJvZ'><ins id='fVJvZ'></ins><ul id='fVJvZ'></ul><sub id='fVJvZ'></sub></form><legend id='fVJvZ'></legend><bdo id='fVJvZ'><pre id='fVJvZ'><center id='fVJvZ'></center></pre></bdo></b><th id='fVJvZ'></th></span></q></dt></tr></i><div id='fVJvZ'><tfoot id='fVJvZ'></tfoot><dl id='fVJvZ'><fieldset id='fVJvZ'></fieldset></dl></div>
                3. <tfoot id='fVJvZ'></tfoot>