python function - a function object
laboratory
When the function is defined, it is similar to a = 1, a function called variable name
def zx():
pass
print(zx)
zx=21
print(zx)
<function zx at 0x000001D825F73E18>
21
Four functions function object
1. references
def func():
print('zx')
return "返回值"
f = func
print(f)
print(f())
<AT 0x0000024231873E18 function FUNC>
ZX
Return value
2 can be used as an argument to a function
def func():
print("zx")
def foo(m):
m()
foo(func)
ZX
3. can be used as the return value of the function
def zx():
print("zx")
def zx2():
return zx
zx2()()
zx
4. The container can be used as an element of type
def zx():
print("zx")
def zx2():
return zx
def zx3():
print("大家好")
x=[zx,zx2,zx3]
x[2]()
Hello everyone