Python math.prod() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Python 3.8+

Definition

math.prod(iterable, *, start=1) multiplies all items of iterable together, starting from start (which defaults to 1).

Added in Python 3.8 as the multiplicative counterpart to built-in sum(), it preserves exact int results when all inputs are integers and returns start when the iterable is empty.

math.prod() is a function in Python's standard math module: import it with import math and call math.prod(...), or import the name directly with from math import prod. Added in Python 3.8.

Syntax

Import math and pass an iterable, plus optional keyword-only start (Python 3.8+).

python
import math

total = math.prod(values)
scaled = math.prod(values, start=10)
CallWhat it does
math.prod([2, 3, 4])Returns 24 (int).
math.prod([2, 3, 4], start=10)Returns 240 (keyword-only start).
math.prod([])Returns 1 (default start for empty iterable).
math.prod([2, 0.5])Returns 1.0 (float promotion).

Notice start is keyword-only: passing math.prod([2, 3], 10) positionally raises TypeError, unlike built-in sum().

Function signatures
python
math.prod(iterable, /, *, start=1)
# added in Python 3.8; start is keyword-only

Parameters

ParameterDescription
iterableRequired positional iterable of numbers (list, tuple, range, generator, etc.).
startOptional keyword-only starting value, defaulting to 1.

Return Value

Return ValueDescription
int or floatExact int when all items and start are ints; promotes to float if any element is a float.

Python Examples

Example 1 — Multiply Growth Factors and Integer Lists

Chain yearly investment multipliers and integer factors cleanly without writing a loop.

python
import math

factors = [1.05, 1.02, 0.98, 1.10]
growth = math.prod(factors)
print(f"net factor: {growth:.4f}")
print("int product:", math.prod([2, 3, 4, 5]))

How It Works

  1. Chained float multipliers. Multiplying all four yearly ratios calculates total cumulative growth in one call.
  2. Formatted net multiplier. Four decimal places show a net 15.45% gain across the period.
  3. Integers stay integers. Multiplying [2, 3, 4, 5] returns exact integer 120.

Example 2 — Use Keyword start and Handle Empty Iterables

Scale products with start=10, inspect empty lists, and catch positional-arg TypeError.

python
import math

print(math.prod([2, 3, 4], start=10))
print(math.prod([]), math.prod([], start=5))

try:
    math.prod([2, 3], 10)
except TypeError:
    print("start must be passed by keyword")

How It Works

  1. Initial multiplier. Setting start=10 begins accumulation at ten instead of one, yielding 240.
  2. Empty iterable returns start. An empty list returns default 1, or custom start=5.
  3. Keyword-only enforcement. Passing 10 positionally raises TypeError.

Example 3 — Multiply Ranges, Generators, and Mixed Numeric Types

Compute factorials from range(), multiply primes, and watch float promotion.

python
import math

print("7! via range:", math.prod(range(1, 8)))
primes = (p for p in [2, 3, 5, 7, 11, 13])
print("primorial   :", math.prod(primes))
mixed = math.prod([2, 3, 0.5])
print("mixed       :", mixed, type(mixed).__name__)

How It Works

  1. Range product. Passing range(1, 8) multiplies 1 through 7 cleanly without creating a list.
  2. Lazy generator input. Any generator expression works directly inside math.prod().
  3. Float promotion rule. Including a single float 0.5 promotes the product to 3.0 (float).

Frequently Asked Questions

math.prod() was added in Python 3.8.
Because start is a keyword-only parameter in math.prod(). Write math.prod([2, 3], start=10).
1, the default value of start.
It returns an int if all inputs and start are integers, and promotes to float (or complex/Decimal) according to normal Python multiplication rules.
prod() is the multiplicative equivalent of built-in sum(), starting at 1 instead of 0.

Next: math.radians()

Convert angle x from degrees to radians.

radians() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful