Functions are first-class objects, i.e. function may be used as the data processing.
def func():
print('from func')
print(func)
<function func at 0x10af72f28>
Dian four functions a function object
- Side of the function refers to the function name, the function name points to the function stored in the memory address
1. references
x = 'hello nick'
y = x
f = func
print(f)
<function func at 0x10af72f28>
2. as a parameter passed to a function
len(x)
def foo(m):
m()
foo(func)
from func
3. The return value can be used as a function of
def foo(x):
return x
res = foo(func)
print(res)
res()
<function func at 0x10af72f28> from func
4. The types of elements can be used as a container
l = [x]
function_list = [func]
function_list[0]()
from func