Python Higher Order Functions

Definition
Function that take other functions as arguments are also called higher order functions.

def inc(x):
    return x + 1

def dec(x):
    return x - 1

def operate(func, x):
    result = func(x)
    return result


>>> operate(inc,3)
4
>>> operate(dec,3)
2


Use Cases
In functional programming.

Courtesy
https://www.programiz.com


Comments

Popular posts from this blog

Python Decorators

Python Closures