Untitled


#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