首页 > 其他 > 详细

函数闭包知识点

时间:2018-09-22 15:54:22      阅读:239      评论:0      收藏:0      [点我收藏+]
#闭包:嵌套函数,内部函数调用外部函数的变量
# 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()

 

函数闭包知识点

原文:https://www.cnblogs.com/limw/p/9690192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!