Python math.prod() Method
Python math.prod()The method is used to calculate the product of all elements in an iterable object.
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 object.
- start-- Optional, the starting value. Default value is 1.
Return Value
A floating-point value or an integer, the product of the iterable elements. The type is determined based on the elements: if all elements are integers, an integer is returned; if any element is a float, a float is returned.
Example
The following example calculates the product of iterable elements:
Example
# Import the math package
import math
# Calculate the product of iterable elements
sequence = (2, 2, 2)
print(math.prod(sequence))
import math
# Calculate the product of iterable elements
sequence = (2, 2, 2)
print(math.prod(sequence))
Output result:
8Other Extensions
Python math Module