- Higher-order functions are the functions that take other functions as arguments. This is extremely common in calculus and math. In Python, we can define or use higher-order functions as well.
- For example, the Python map() function is a higher-order function. The map() function takes two parameters, function and iterable (such as a list), and returns a map object (which we can iterate through).
- Also, the Python filter() function returns a filter object that consists of the numbers on which the first parameter function returns True
- f(x) = 2x +3 , higher order function 類似數學中的 g(f(x))

#higher order function
def higherOrder(fn):
fn()
def smallfunc():
print("Hello from small function")
higherOrder(smallfunc) #跑smallfunc 跟跑 smallfunc()的區別
higherOrder(smallfunc()) # 不太懂跑error message 的用意
-----------------------------------------------------
[Running] python -u "d:\\2022_python_全攻略\\tempCodeRunnerFile.py"
Hello from small function
Hello from small function
Traceback (most recent call last):
File "d:\\2022_python_\\u5168\\u653b\\u7565\\tempCodeRunnerFile.py", line 10, in <module>
higherOrder(smallfunc()) # \\u4e0d\\u592a\\u61c2\\u8dd1error message \\u7684\\u7528\\u610f
File "d:\\2022_python_\\u5168\\u653b\\u7565\\tempCodeRunnerFile.py", line 2, in higherOrder
fn()
TypeError: 'NoneType' object is not callable
# map function (high order function)
def square(num):
return num ** 2
mylist = [-10, 3, 8, 9, 10]
print(map(square, mylist)) # print 出map function 的位置
for item in map(square, mylist): #for loop 出Map value
print(item)
----------------------------------------------
<map object at 0x000001EE734BD190>
100
9
64
81
100