should work with an arbitrary ( )which is most conveniently accomplished by passing python function (xas an argument to the function consider the example of approximating the second derivative (xby centered finite differencesf (xf ( (xf ( hh the corresponding python function looks like def diff (fxh= - ) ( ( - * (xf( + ))/float( *hreturn we see that the function is passed to the function just as any other argumentand is called as regular function inside diff of coursefor this to workwe need to actually send callable function as the first argument to diff if we send something elselike number or stringthe code will stop with an error when it tries to make the call ( -hin the next line such potential errors are part of the price we pay for python' flexibility we can pass any argument to functionbut the object we pass must be possible to use as intended inside the function as noted abovefor more complex functionsit is useful to include doc string that specifies the types of arguments the function expects lambda functions for compact inline function definitions in order to use the function diff aboveone would standardly define our (xas python functionand then pass it as an argument to diff the following code shows an exampledef ( )return ** df diff ( , print(df the concept known as lambda function offers compact way to define functionswhich can be convenient for the present application using the keyword lambdawe can define our on single lineas followsf lambda xx** more generallya lambda function defined by somefunc lambda some_expression is equivalent to def somefunc( )return some_expression it could be natural to ask whether anything is really gained hereand whether it is useful to introduce new concept just to reduce function definition