0

What is a difference between these examples and which one should I use:

class Foo:

class Foo():

class Foo(object):

I think my question is unique, because in a linked proposed duplicate question it doesn't say the difference between class Foo: and class Foo():

Hrvoje T
  • 2,709
  • 4
  • 25
  • 34

1 Answers1

4

class Foo: is essentially a syntactic shortcut for class Foo():. The difference between class Foo(): and class Foo(object): only exists in Python 2, where the former creates an old-style class and the latter creates a new-style class. In Python 3, all three are identical, as only new-style classes exist.

chepner
  • 446,329
  • 63
  • 468
  • 610