Python装饰器2-嵌套函数

2019-06-15  本文已影响0人  dnsir

嵌套函数

嵌套函数(Nested function)是在另一个函数(即:封闭函数)中定义的函数

引用自:https://blog.csdn.net/liang19890820/article/details/73864242

def hi(name = "yasoob"):
    print("now you are inside the hi() function")

    def greet():
        return "you are in greet() function"

    def welcome():
        return "you are in welcome() function"

    print(greet())
    print(welcome())
    print("back in hi() function")

hi()

执行结果:

now you are inside the hi() function
you are in greet() function
you are in welcome() function
back in hi() function

小结

通过该示例,学习Python中嵌套函数的用法,装饰器一部分特性体现在也是一个嵌套函数。

上一篇 下一篇

猜你喜欢

热点阅读