Functions and methods are first-class objects in Python, so if you want to pass a function to another function, you can just treat it as any other object.
To bind a function object to a specific context, you can use either nested scopes or callable objects. For example, suppose you wanted to define linear(a,b) which returns a function f(x) that computes the value a*x+b.
Using nested scopes:
def linear(a, b):
def result(x):
return a*x + b
return result
Or using a callable object:
class linear:
def __init__(self, a, b):
self.a, self.b = a,b
def __call__(self, x):
return self.a * x + self.b
In both cases:
taxes = linear(0.3, 2)
gives a callable object where taxes(10e6) == 0.3 * 10e6 + 2.
For More :
https://thenewcircle.com/static/bookshelf/python_fundamentals_tutorial/functional_programming.html