subclass of object

Steve Holden steve at
Fri Apr 2 07:57:35 EDT 2010

Jason Friedman wrote:
> Hi, what is the difference between:
> def MyClass(object):
>     pass
> and
> def MyClass():
>     pass

In Python 3, nothing. In Python 2, the former gets you a subclass of
object whereas the latter gets you an instance of <type 'classobj'>, for
compatibility with pre-2.2 versions.

For most practical purposes there is no difference, so it doesn't matter
until it matters, so to speak. Unless you are noticing unexpected
behavior in your programs you probably don't need to worry (though you
might want to use the first form to ensure better Python 3 compatibility).

Steve Holden           +1 571 484 6266   +1 800 494 3119
See PyCon Talks from Atlanta 2010
Holden Web LLC       

More information about the Python-list mailing list