函数闭包知识点

#闭包:嵌套函数,内部函数调用外部函数的变量
# 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()

 

posted on 2018-09-22 15:22  魔王李等猴哥的日子  阅读(80)  评论(0编辑  收藏  举报

导航