def derivative(f): def g(x): return (f(x+0.0001)-f(x))/0.0001 return g def f(x): return x**2 derivative(f) derivative(f)(5) df = derivative(f) df(5)