1

I know the following works but i never understood what the difference are between

class Animal:

class Animal():

class Animal(object):

Is this just a style difference or something more to it?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
ealeon
  • 12,074
  • 24
  • 92
  • 173
  • 3
    http://stackoverflow.com/questions/54867/what-is-the-difference-between-old-style-and-new-style-classes-in-python – MSeifert Feb 07 '16 at 21:41

1 Answers1

2

In Python 3, all three are the same, i.e. all derive from object.

Asclepius
  • 57,944
  • 17
  • 167
  • 143
Clodion
  • 1,017
  • 6
  • 12
  • Yes this is the case in Python 3, but (very importantly) this is NOT the case in Python 2, where omitting the inheritance of object creates an old-style class. As a rule of thumb, always make new-style classes in Python 2. – Ulf Aslak Feb 07 '16 at 21:53
  • @UlfAslak: yes sure! In `Python 2` it was very important! As such `python 3` if very nice! – Clodion Feb 07 '16 at 21:56