码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-09-05 09:01:37      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:turn   内部函数   with   url   一个   https   out   lib   函数   

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

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




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

标签:turn   内部函数   with   url   一个   https   out   lib   函数   

原文地址:https://www.cnblogs.com/jly1/p/9589311.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!