标签: list multiplying
如何将列表中的所有元素自身相乘(python 2.7)?
例如:
B = [2,3,4]
输出:2 * 3 * 4 = 24
答案 0 :(得分:0)
简单
mul=1 for i in b: mul =mul*i print mul
答案 1 :(得分:0)
import operator import functools Result = functools.reduce(operator.mul, b, 1) print(Result)