Python 装饰器

#一、装饰器的作用就是给已经实现的功能再扩展新的功能
#二、无参数的
 1 # def wohaoshuai1(func):
 2 #     print("wohaoshuai1")
 3 #     return func
 4 #
 5 # @wohaoshuai1
 6 # def wohaoshuai2():
 7 #     print("wohaoshuai2")
 8 #
 9 # # 与上面装饰内容原理相同
10 # # wohaoshuai2 = wohaoshuai1(wohaoshuai2)
11 # wohaoshuai2()
#三、有参数
 1 # def wohaoshuai1(function):
 2 #     def inner(*args,**kwargs):
 3 #         print("wohaoshuai1")
 4 #         return function(*args,**kwargs)
 5 #     print(inner)
 6 #     return inner
 7 #
 8 # @wohaoshuai1
 9 # def wohaoshuai2(name,wohaoshuai,c):
10 #     print("wohaoshuai2 {0} {1} {2}".format(name,wohaoshuai,c))
11 #     return 1
12 #
13 # print(wohaoshuai2)
14 # a = wohaoshuai2("aaa","bbb",c=1)
15 # print(a)
16 #
17 # <function wohaoshuai1.<locals>.inner at 0x05536108>
18 # <function wohaoshuai1.<locals>.inner at 0x05536108>
19 # wohaoshuai1
20 # wohaoshuai2 aaa bbb 1
21 # 1

 

转载于:https://www.cnblogs.com/Presley-lpc/p/9218190.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值