函数_函数进阶_闭包和函数的嵌套和作用域链

#闭包:嵌套的函数,内部函数调用外部函数的变量

# 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()




猜你喜欢

转载自www.cnblogs.com/jly1/p/9589311.html
今日推荐