闭包,装饰器

 1 def d(F):
 2     def new_F(a, b):
 3         print("input", a, b)
 4         return F(a, b)
 5     return new_F
 6 
 7 
 8 def s(a, b):
 9     return a**2 + b**2
10 
11 s = d(s)
12 print s(3,4)

 装饰器:

 1 def d(F):
 2     def new_F(a):
 3         print("input", a)
 4         b = 4
 5         return F(a, b)
 6     return new_F
 7 
 8 
 9 @d
10 def s(a, b):
11     return a**2 + b**2
12 
13 
14 print s(3)

 

posted @ 2017-06-01 15:28  扫驴  阅读(129)  评论(0编辑  收藏  举报