3

Before py2.6 it's been answered here. Difference between class foo and class foo(object) in Python

But for python2.6+ and python3.x, is the first one wrong?

class Foo(): pass vs class Foo(object): pass

Community
  • 1
  • 1
ninMonkey
  • 6,940
  • 6
  • 33
  • 66

1 Answers1

3

For Python2.6+, before Python 3.0, the former creates an old-style class while the latter creates a new-style class. In Python 3.0, both create a new-style. The first isn't wrong, but for anything before 3.0 it has different semantics than the latter and is typically discouraged.

Michael Aaron Safyan
  • 90,931
  • 15
  • 133
  • 196