Easy Tutorial
❮ Ref Math Dist Python Func Number Asin ❯

Python math.prod() Method

Python math Module

The math.prod() method in Python is used to calculate the product of all elements in an iterable.

Python Version: 3.8

Syntax

The syntax for the math.prod() method is as follows:

math.prod(iterable, start)

Parameter Description:

Return Value

A float or an integer, representing the product of the iterable elements. The type is determined by the elements; if all elements are integers, the return value is an integer; if any element is a float, the return value is a float.

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))

Output Result:

8

Python math Module

❮ Ref Math Dist Python Func Number Asin ❯