+ 2
A function calling function in itself can be of two ways: 1. A decorator function: being an outer function having another function nested within. The outer function. executes and calls the inner function and after the inner executes its result get returned to the outer function. Eg. def decorator(): def wrapper(): print("hello World") return wrapper 2. A Recursive Function: a function calls itself within its execution block. Notice below the function multiplier calls itself again causing a loop until the loop hits the base case x == 0, then it returns 1. Eg. def multiplier(x): if x == 0: return 1 return multiplier(x - 1) * x
26th Jul 2016, 1:23 AM
Benneth Yankey
Benneth Yankey - avatar