1 #閉包:內部函數調用內部函數 2 def outer(): 3 a = 1 4 def inner(): 5 print(a) 6 7 return inner 8 9 #print(inner.__closure__) 10 inn = outer() 11 inn() 12 13 #例子 14 15 from urllib.request import urlopen 16 def get_url(): 17 url = 'https://stock.tuchong.com/?source=extbaidudkey155&utm_source=extbaidudkey155 ' 18 def get(): 19 ret = urlopen(url).read() 20 print(ret) 21 return get 22 inn_func = get_url() 23 inn_func()