Python math.prod() Method
Python math.prod() The method computes the product of all elements in an iterable.
Python version: 3.8
Syntax
The syntax of the math.prod() method is as follows:
math.prod(iterable, start)
Parameter Description:
- iterable -- required, an iterable.
- start -- optional, the starting value. Defaults to 1.
Return Value
A floating-point value or integer, the product of the iterable's elements; the type depends on the elements, returning an integer if all elements are integers and a floating-point number if any element is a float.
Example
The following example computes the product of iterable elements:
Example
Import the math package
import
math
Compute the product of iterable elements
sequence
=
(
2
,
2
,
2
)
(
math
.
prod
(
sequence
)
)
Output result:
8
Python math Module