new-style class or old-style class?

Roy Smith roy at panix.com
Wed Sep 26 09:12:33 EDT 2012


In article <2e8a9e88-9e7e-43f7-a070-ea9054e625f2 at googlegroups.com>,
 Jayden <jayden.shui at gmail.com> wrote:

> In learning Python, I found there are two types of classes? Which one are 
> widely used in new Python code? Is the new-style much better than old-style? 
> Thanks!!

If you're just learning Python 2.x, you might as well use new-style 
classes, since that's what all classes are in 3.x.

On the other hand, if you're just learning, it probably doesn't matter 
which kind you use.  Until you get into some pretty sophisticated stuff, 
you won't notice any difference between the two.

On the third hand, all it takes to create a new-style class is to have 
it inherit from object.  It's no big deal to write

>>> class Foo(object):

instead of just

>>> class Foo:

so you might as well use new-style classes :-)



More information about the Python-list mailing list