<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中的旧样式类和新样式类有什么区别?

      What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
        <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中的旧样式类和新样式类有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                How to break out of multiple loops?(如何打破多个循环?)
                How to put the legend out of the plot(如何将传说从情节中剔除)
                Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)
                Difference between modes a, a+, w, w+, and r+ in built-in open function?(内置 open 函数中模式 a、a+、w、w+ 和 r+ 的区别?)

                  <tbody id='fVJvZ'></tbody>

                  <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>