Simple python inheritance

Viewed 5534
class Animal(object):
    def __init__(self, nlegs=4):
        print '__init__ Animal'
        self.nlegs = nlegs

class Cat(Animal):
    def __init__(self, talk='meow'):
        print '__init__ Cat'
        self.talk = talk

class Dog(Animal):
    def __init__(self, talk='woof'):
        print '__init__ Dog'
        self.talk = talk
  1. Why does my cat tom = Cat() not have an nlegs attribute?
  2. Should we explicitly call Animal.__init__() from within Cat.__init__, or should we be doing something more fancy, say, with super?
  3. What about if I want to create a cat with 5 legs, do I need to add additional arguments to the Cat.__init__ interface?
3 Answers
Related