小编ral*_*llo的帖子

如何将列表中的所有元素彼此相乘?

我试图将列表中的所有数字彼此相乘

a = [2,3,4]
for number in a:
        total = 1 
        total *= number 
return total 
Run Code Online (Sandbox Code Playgroud)

输出应该是 24,但由于某种原因我得到 4。为什么会这样?

python math list multiplication operator-keyword

0
推荐指数
1
解决办法
149
查看次数

标签 统计

list ×1

math ×1

multiplication ×1

operator-keyword ×1

python ×1