Python 小程序(2)

Python提供的sum()函数可以接受一个list并求和,请编写一个prod()函数,可以接受一个list并利用reduce()求积:

1 from functools import reduce
2 def prod(x,y):
3     return x * y
4 if __name__ == '__main__':
5     L=[3, 5, 7, 9]
6     print(reduce(prod,L))
原文地址:https://www.cnblogs.com/lizimu/p/11023999.html