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
- Why does my cat
tom = Cat() not have an nlegs attribute?
- Should we explicitly call
Animal.__init__() from within Cat.__init__, or should we be doing something more fancy, say, with super?
- What about if I want to create a cat with 5 legs, do I need to add additional arguments to the
Cat.__init__ interface?