4

In Python 2, classes should explicitly be defined as subclasses of 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 use Python 2.7 and as I know in 2.7 class inherits from object.

P̲̳x͓L̳
  • 3,615
  • 3
  • 29
  • 37
  • 1
    read this for an explanation of new style classes http://stackoverflow.com/questions/4015417/python-class-inherits-object? – dannymilsom Mar 31 '14 at 16:25
  • I'm pretty sure `class` inherits from `object` in python >=3.0, but not 2.7. You still have to explicitly inherit from `object` in python 2.x. – SethMMorton Mar 31 '14 at 16:44

1 Answers1

4

That is a so-called "new style object", introduced in python 2.2.

New style objects have a different object model to classic objects, and some things won't work properly with old style objects, for instance, super(), @property and descriptors.

More on it in the famous question:

Please also refer to:

Also, please note that there is a difference between them only in Python 2. In Python 3 you have no difference between these two types of declaration anymore (I know that your question is about Python 2, just a small note).

Community
  • 1
  • 1
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144