class paraboladef __init__(selfc )self self self def __call__(selfx)return self * ** self * self def table(selflrn)"""return table with points for < < "" 'for in linspace(lrn) self(xs +'% % \ (xyreturn class line(parabola)def __init__(selfc )super(__init__( notice that this version allows even more code reuse than the previous onesince both __call__ and table can be reused without changes exampleclasses for numerical differentiation common tasks in scientific computingsuch as differentiation and integrationcan be carried out with large variety of numerical methods many such methods are closely relatedand can be easily grouped into families of methods that are very suitable for implementation in class hierarchy as first examplewe consider methods for numerical differentiation the simplest formula is one-sided finite differencef (xf ( hf (xh which can be implemented in the following classclass derivativedef __init__(selffh= - )self self float(hdef __call__(selfx)fh self fself return ( ( +hf( ))/ make short forms to use the derivative classwe simply define function ( )create an instance of the classand call it as if it were regular function (effectively calling the __call__ method behind the scenes)