1. 程式人生 > >函數_函數進階_閉包和函數的嵌套和作用域鏈

函數_函數進階_閉包和函數的嵌套和作用域鏈

rom 一個 調用 nco pri write enc get() get

#閉包:嵌套的函數,內部函數調用外部函數的變量

# def outer():
# a = 1
# def inner():
# print(a)
# # print(inner.__closure__) #說明是一個閉包
# return inner
#
# inn = outer()
#
# inn() #在一個函數的外部使用內部的函數

#使用閉包的好處就是隨意的使用變量


import urllib #模塊
# from urllib.request import urlopen
# ret = urlopen("https://www.ishsh.com/").read()
#
# with open("123.txt", "w", encoding="utf-8") as f:
# f.write(str(ret))
# def get_utl():
# url = "https://www.ishsh.com/"
# def get():
# ret = urlopen(url).read()
# print(ret)
# return get
#
# get_func = get_utl()
# get_utl()




函數_函數進階_閉包和函數的嵌套和作用域鏈