What is the difference between a class definition

In Python 2, classes must be explicitly defined as subclasses of an object. In Python 3, this will be the default.

>>> class A(object):
    pass

>>> class B():
    pass

>>> type(B)
<type 'classobj'>
>>> type(A)
<type 'type'>

I am using Python 2.7 and, as I know, in 2.7 classinherits from object.

+4
source share
1 answer

This is the so-called "new style object" introduced in python 2.2.

New style objects have a different object model for classic objects, and some things will not work properly with old style objects, such as super (), @property, and descriptors.

Read more about this in the famous question:

See also:

, Python 2. Python 3 ( , Python 2, ).

+4

Source: https://habr.com/ru/post/1534290/


All Articles