美文网首页
Python装饰器4-函数参数是函数名

Python装饰器4-函数参数是函数名

作者: dnsir | 来源:发表于2019-06-15 11:16 被阅读0次

    Python的函数参数可以是可调用对象

    对于函数名就是一个可调用对象

    #! -*- coding: utf-8 -*-
    """
    将函数作为参数传递给另外一个函数
    """
    
    def hi():
        return "hi yasoob"
    
    def doSomethingBeforeHi(func):
        print("I am dong some boring work before hi()")
        print(func())
    
    doSomethingBeforeHi(hi)
    

    小结

    Python装饰器的语法是将被装饰的函数作为参数传递到装饰器函数

    相关文章

      网友评论

          本文标题:Python装饰器4-函数参数是函数名

          本文链接:https://www.haomeiwen.com/subject/opzvfctx.html