闭包函数
闭包的定义
内部的函数引用了外部函数的变量
def f1(b): # 闭包的常用状态
def f2():
print(b)
return f2
ff = f1('bbb')
ff()
def f1(): # 从内部函数返回一个值到全局
b = 10
def f2():
return b
return f2()
print(f1())
from urllib.request import urlopen
# ret = urlopen('https://www.baidu.com').read()
# print(ret)
def get_url(url):
def read1():
ret = urlopen(url).read()
print(ret)
return read1
read_func = get_url('https://www.baidu.com')
read_func()
