至少有四种写法
Topic source第五种写法,基本思路都差不多,写法上有些差异。
def product(*args):
if not len(args):
raise TypeError
lst=[str(i) for i in list(args)]
result="*".join(lst)
return eval(result)
第六种写法,使用嵌套函数:
def product(*args):
def cal(lst):
if len(lst) == 0:
raise TypeError
if len(lst) == 1:
return lst[0]
else:
return lst.pop() * cal(lst)
return cal(list(args))
- 1
要四个字哦
写法一:
写法二:
写法三:
写法四:
均能实现最终的效果,供大家参考。