1. Anonymous functions
def calc(x, y): return x+ y func = lambda x, y: x+ y print(calc(1, 2)) print(func(1, 2))
format: lambda variable: logical
Anonymous functions support up to ternary operations and cannot implement more complex logic
def calc(x, y): if x < y: return x+y else: return x - y func = lambda x, y: x+y if x < y else x - y print(calc(1, 2)) print(func(1, 2))
Second, higher-order functions: accept one or more functions as parameters or return another function
3. Recursion
Fourth, the decorator