math.prod

Full name
math.prod
Library
math
Syntax

math.prod(iterable, start = 1)

Description

The math.prod function calculates the product of all elements of the iterable included as the first argument. The start parameter determines the first value to consider in the multiplication.

If the iterable is empty, the value start is returned.

Parameters
  • iterable: Iterable whose elements you want to multiply. These can be whole, real, or complex numbers.
  • start: First value to consider in the multiplication. By default it takes the value 1.
Result

The result returned by the math.prod function is a number, integer, real, or complex.

Examples

In this example we want to calculate the product of the numbers 2, 3 and 1.5:

math.prod([2, 3, 1.5])

9.0

We repeat the same example but forcing the first value to consider in the multiplication to be 4:

math.prod([2, 3, 1.5], start = 4)

24

The elements of the iterable can be complex numbers:

math.prod([2, 3, 1 + 2j])

(6 + 12j)

If the iterable is empty, the start value is returned:

math.prod([])

1

math.prod([], start = 2.5)

2.5

Submitted by admin on Thu, 01/28/2021 - 10:10