52e. Pass functions as arguments

We can also pass functions as arguments.

this way, we can use functions even inside a function.

The main difference between recursion & this is that:

  • in recursion, we are using the same function inside a function.
  • in this, we are using another function.

Example:


def appl(fx, value):
  return 6 + fx(value)

double = lambda x: x * 2
cube = lambda x: x * x * x
avg = lambda x, y, z: (x + y + z) / 3     # function to calculate average.


print(appl(double , 2))

# Output:
10