Application of Function name
application categories for function names:
A function is a special variable (which can be used as a variable)
* Memory address of function name corresponding function
* Function names can be used as elements of container class data
* Function name can be used as parameter of function
* Function name can be used as return value of function
* Function names can be arbitrarily assigned.
There is a name for such a function: the first class of functions
1. Print function name, display function memory address
Example:
# def func1 ():
# Print (666)
# Print (FUNC1)
Results:
# <function func1 at 0x000000000258f9d8>
2 function names can be used as elements of container class data
Example:
Def func1 ():
Print (111)
Def FUNC2 ():
Print (222)
Def func3 ():
Print (333)
L1 = [Func1, Func2, func3]
For I in L1:
I () # # # #函数名加括号即执行函数
3 function names can be used as arguments to functions
Example:
Def func1 ():
Print (111)
def func2 (x):
Print (x)
X ()
Print (222)
Func2 (FUNC1)
4 function names can be used as return values for functions
Example:
Def func1 ():
Return 111
def func2 (x): # x = func1
Print (222)
return x
ret = Func2 (func1) # func1
Print (ret ())
Print (ret)
Results:
222
111
<function func1 at 0x0215d810>
Description
#向这样的函数名 have a term: first Class object
Python contains functions such as everything is an object, the function as the first class object, support assignment to the variable, as a parameter to other functions, as the return value of other functions, supporting the nesting of functions, the implementation of the __call__ method of the class instance object can also be called as a function.
Python Function name Application