#!/usr/bin/python
# -*- encoding=utf-8 -*-

def test(number):

    # 在函数里面再定义一个函数,并且这个函数用到外边函数的变量,那么将这个函数以及用到的一些变量称之为闭包
    def test_in(number_in):
        print("in test_in 函数,number_in is %d" %number_in)
        return number+number_in

    # 其实这里返回的就是闭包的结果
    return test_in

ret = test(20)
print(ret(30))

Python高级笔记(十)闭包

 

相关文章:

  • 2021-07-06
  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
  • 2021-07-17
  • 2021-11-23
  • 2021-07-26
猜你喜欢
  • 2021-10-18
  • 2021-10-27
  • 2021-05-18
  • 2021-07-11
  • 2021-08-20
  • 2022-03-08
  • 2021-07-11
相关资源
相似解决方案