閉包 返回函數對象


第四點,要知道,函數的返回值也可以是函數對象(閉包),比如下面這個例子:


def func_closure():
    def get_message(message):
        print '11111111111111111111111111111'
        print('Got a message: {}'.format(message))
    return get_message

send_message = func_closure()
print send_message
print type(send_message)
send_message('hello world')



C:\Python27\python.exe "C:/Users/TLCB/PycharmProjects/untitled2/python study/fun1.py"
<function get_message at 0x00502570>
<type 'function'>
11111111111111111111111111111
Got a message: hello world

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章