1. 程式人生 > >使用Python中的reduce()函式求積

使用Python中的reduce()函式求積

編寫一個prod()函式,可以接受一個list並利用reduce()求積。

from functools import reduce
def prod(x,y):
	return x * y
L = reduce(prod,[3,5,7,9])
print(L)

列印結果如下: