美文网首页自动化学习-python
2018-10-28:reduce练习

2018-10-28:reduce练习

作者: 种树在此时 | 来源:发表于2018-10-31 00:03 被阅读0次

-- coding: utf-8 --

from functools import reduce
def prod(L):
def fn(x, y):
return x * y
return reduce(fn, L)
print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9]))
if prod([3, 5, 7, 9]) == 945:
print('测试成功!')
else:
print('测试失败!')

相关文章

网友评论

    本文标题:2018-10-28:reduce练习

    本文链接:https://www.haomeiwen.com/subject/dmqotqtx.html