函数的嵌套

# a = 1
# def outer():
#     a = 2
#     def inner():
#         a = 3
#
#         def inner2():
#             nonlocal a            #nonlocal只能用于局部变量,找最近一层的局部变量
#             a += 1
#         inner2()
#         print('inner() a', a)
#
#     inner()
#     print('##a##', a)
#
# outer()
# print(a)
#
#
# def func():
#     print('func')
#
#
# def func2():
#     print('func2')
#
#
# def func3(f):
#     f()
#     return f  # 函数名可以作为函数的返回值
#
#
# func1 = func  # 函数名可以赋值
# print(func1)  # 函数名就是内存地址,输出func1内存地址
# func1()
#
# l = [func, func2]  # 函数名可以作为容器类型的元素
# print(l)
#
# a = func3(func2)  # 函数名可以作为函数的参数
# a()
原文地址:https://www.cnblogs.com/hhsh/p/9534973.html