In array [1,5,6]
, I have 3 elements and I want to multiply them like: 1 * 5 * 6
I don't want did it like that:
array[0] * array[1] * array[2]
I want it automatically no matter how big the array is.
In array [1,5,6]
, I have 3 elements and I want to multiply them like: 1 * 5 * 6
I don't want did it like that:
array[0] * array[1] * array[2]
I want it automatically no matter how big the array is.
You can functools.reduce
your array by operator.mul
tiplication:
from operator import mul
from functools import reduce
array = [1, 5, 6]
reduce(mul, array)
# 30