First page Back Continue Last page Overview Graphics

Without redundant code

To avoid redundant code we can define a class with the method and inherit from this class:

class Answers:

def the_answer(self, *args):

return 42

class Philosopher1(Answers):

pass

class Philosopher2(Answers):

pass

class Philosopher3(Answers):

pass

plato = Philosopher1()

print(plato.the_answer())

kant = Philosopher2()

# let's see what Kant has to say :-)

print(kant.the_answer())