Intro: The function parentheses represent the function that is called, without parentheses representing the function itself (the name of the letter)
For example:
# seek absolute value built-in function abs>>>abs ( -10) # call Function # return call result >> >abs # function itself <built- in function abs> # returns the function itself
Higher-order function definitions:
A variable can point to a function, a function can receive a variable, and a function may receive another function as a parameter, which is called a higher order function.
n = 1def func1 (x, y): return x+ydef FUNC2: return XF = Func2 #变量指向函数本身 instead of calling function f (n) #函数接收变量, At this point F () is equivalent to Func2 () F (func1 ()) #一个函数接收另一个函数作为参数print (f (func1 ())) #结果3 #func2 () is called the higher order function
The function name is also a variable, if you assign a value to the function name, then you cannot call the function at the back, so you must not do so.
>>> ABS = 10>>> ABS ( -10) Traceback (most recent) :"<stdin>< /c8>" in <module>'int' is not callable
Summarize:
A higher-order function is required only if one of the following conditions is true:
1. One function receives another or more functions as arguments
2. Function return returns another function itself
1 def f (x): 2 return abs,x # returns the ABS function name, which is the return ABS function itself 34#F () is also a higher order function
python3--Higher order functions