Python-Core-50-Courses icon indicating copy to clipboard operation
Python-Core-50-Courses copied to clipboard

python-core-50,第20课发现错误

Open ksi1110 opened this issue 4 years ago • 2 comments

def calc(*args, **kwargs): result = 0 for arg in args: result += arg for value in kwargs.values(): result += value ### return total

最后应该是return result

ksi1110 avatar Feb 21 '21 12:02 ksi1110

函数使用进阶,高阶函数,发现代码位置错误 import operator

print(calc(init_value=0, op=operator.add, 1, 2, 3, x=4, y=5)) # 15 print(calc(init_value=1, op=operator.mul, 1, 2, x=3, y=4, z=5)) # 120

位置参数应该写在关键字参数前面,正确代码为: print(calc(1, 2, 3, init_value=0, op=operator.add, x=4, y=5)) 或者 print(calc(1, 2, x=3, y=4, z=5, init_value=1, op=operator.mul))

ksi1110 avatar Feb 22 '21 03:02 ksi1110

i also find out this mistake,please change it

yegetables avatar Mar 14 '21 11:03 yegetables