python学习——闭包

def outer():

  a = 10

  def inner():

    print(a)

  return inner

ret = outer()#这种写法只加载了一次外层函数,所以执行的时候a = 10 只执行了一次

ret()

ret()

posted @ 2019-08-09 09:23  陪伴is最长情的告白  阅读(101)  评论(0编辑  收藏  举报