目錄python
函數是第一類對象, 即函數能夠被看成數據處理。函數
def func(): print('from func') print(func)#func 指向一塊內存地址,函數名 #輸出: <function func at 0x000002AD89B5E5E8>
def func(): print('from func') x = 'hello chen' y = x f = func print(f,func) #輸出: <function func at 0x000001CFCD9AE5E8> <function func at 0x000001CFCD9AE5E8>
def func(): print('from func') def foo(m): m() foo(func) #輸出: from func
能夠看成函數的返回值code
def func(): print('from func') def foo(x): return x res = foo(func) print(res) res() #輸出: <function func at 0x000002036E0F4F78> from func
能夠看成容器類元素對象
# 變量名能夠放入容器類數據類型 def func(): print('from func') a= 1 lt = [1, 2, a, func] lt[-1]() #輸出: from func