Starting Python 3.8
, a .prod
function has been included to the math
module in the standard library:
math.prod(iterable, *, start=1)
The method returns the product of a start
value (default: 1) times an iterable of numbers:
import math
math.prod([1, 2, 3, 4, 5, 6])
>>> 720
If the iterable is empty, this will produce 1
(or the start
value, if provided).