函數閉包知識點
阿新 • • 發佈:2018-09-22
clas 嵌套 知識點 req outer color www imp htm
#閉包:嵌套函數,內部函數調用外部函數的變量 # def outer(): # a = 1 # def inner(): # print(a) # inner() # outer() def outer(): a = 1 def inner(): print(a) return inner inn = outer() inn() # import urllib #模塊 from urllib.request import urlopen # ret = urlopen(‘http://www.xiaohua100.cn/index.html‘).read()# print(ret) # def get_url(): # url = ‘http://www.xiaohua100.cn/index.html‘ # ret = urlopen(url).read() # print(ret) # # get_url() def get_url(): url = ‘http://www.xiaohua100.cn/index.html‘ def get(): ret = urlopen(url).read() print(ret) return get get_func = get_url() get_func()
函數閉包知識點