Class definitions deriving from object

Possible Duplicate:
Old style and new style classes in Python
python class inherits object

What's the difference between

class foo: 

and

class foo(object):

Can anyone explain why we are using object in class definition?


In Python 2.x the first declaration is an old-style class and the second version is a new-style class. You should always use new-style classes for new code.

In Python 3 all classes are new-style so there is no difference.

链接地址: http://www.djcxy.com/p/54188.html

上一篇: 类定义中的Python差异

下一篇: 从对象派生的类定义