标签:fun code lis sum uml each not rgs 列表
def sumlist(*arg): return sum(arg) def averageList(*arg): return sum(arg)*1.0/len(arg) def dec(func): def in_dec(*args): if len(args)==0: return 0 for each in args: if not isinstance(each, int): return 0 return func(*args)#这里args前面必须有* return in_dec num=[1,2,3] sum1 = dec(sumlist) print sum1(*num)#必须传入元组,列表前必须加* print sum1(*[1,2,3])#必须传入元组,列表前必须加* print sum1(1,2,‘3‘)#或者以这种形式传入 ave1 = dec(averageList) print ave1(1,2,3,4) print ave1(1,2,3,4,‘3‘)
标签:fun code lis sum uml each not rgs 列表
原文地址:https://www.cnblogs.com/ggzhangxiaochao/p/9007363.html