#####
1.装饰器
例子:
取sumw() 不定参数 + 字典参数 总数+(109, 20)
def sum_add(*args1): #@sum_add(10,20)
print(args1);#10,20
def decorator(func):#sumw(*args,**kwargs) da={"a":1,"b":2,"c":3,"d":4} print(sumw(1,2,3,4,5,**da))
print(func)
def my_sum(*args2,**kwargs):#等同于自定义 sumw(*args,**kwargs) 函数
my_s = 0
for n in args1:
my_s = my_s + n
print(my_s)
return func(*args2,**kwargs) + my_s
return my_sum
return decorator
@sum_add(109, 20)
def sumw(*args,**kwargs):
s = 0
for n in args:
s = s + n
sq=0
for i in kwargs:
sq=sq+kwargs[i]
return s+sq
da={"a":1,"b":2,"c":3,"d":4,"e":5}
# for i in da:
# print(da[i])
print(sumw(1, 2, 3, 4, 5,**da))