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
  • 3,365
  • 4
  • 28
  • 41

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
  • 497,756
  • 71
  • 530
  • 681