Python - Decorators

后端 未结 5 456
礼貌的吻别
礼貌的吻别 2020-12-10 12:32

I\'m trying to learn Decorators . I understood the concept of it and now trying to implement it.

Here is the code that I\'ve written The code is se

5条回答
  •  春和景丽
    2020-12-10 13:04

    this might work.

    def wrapper(func):
        def inner(*args,**kwargs):
            if ((args[0] is int) and (args[1] is int)): pass
            else: return 'invalid values'
        return inner
    @wrapper
    def add(x,y):
        return x+y
    print add('a',2)
    

提交回复
热议问题