Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From <a href="http://docs.python.org/2/reference/datamodel.html#new-style-and-classic-classes" rel="nofollow noreferrer">http://docs.python.org/2/reference/datamodel.html#new-style-and-classic-classes</a> :</p> <blockquote> <p><strong>Up to Python 2.1, old-style classes were the only flavour available to the user.</strong></p> <p>The concept of (old-style) class is unrelated to the concept of type: if <code>x</code> is an instance of an old-style class, then <code>x.__class__</code> designates the class of <code>x</code>, but <code>type(x)</code> is always <code>&lt;type 'instance'&gt;</code>. </p> <p>This reflects the fact that all old-style instances, independently of their class, are implemented with a single built-in type, called instance.</p> <p><strong>New-style classes were introduced in Python 2.2 to unify the concepts of class and type</strong>. A new-style class is simply a user-defined type, no more, no less.</p> <p>If x is an instance of a new-style class, then <code>type(x)</code> is typically the same as <code>x.__class__</code> (although this is not guaranteed – a new-style class instance is permitted to override the value returned for <code>x.__class__</code>).</p> <p><strong>The major motivation for introducing new-style classes is to provide a unified object model with a full meta-model</strong>. </p> <p>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.</p> <p><strong>For compatibility reasons, classes are still old-style by default</strong>. </p> <p>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. </p> <p>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. </p> <p>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.</p> <p><strong>Python 3 only has new-style classes</strong>. </p> <p>No matter if you subclass from <code>object</code> or not, classes are new-style in Python 3.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload