Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

math.prod

Multiplies the members of an iterable beginning with an optional initial factor.

Version: Python 3.14; repository image, production runtime not attested

Syntax

math.prod(iterable, /, *, start=1)

Multiplies the members of an iterable beginning with an optional initial factor.

With empty input the function returns the given starting value.

Multiplication folds numeric elements into a single result. The default initial factor 1 gives 2 × 3 × 4 = 24; a keyword-only start of 7 remains 7 for empty input. Multiplying a list by an integer instead repeats its sequence.

import math
assert math.prod([2, 3, 4], start=10) == 240
assert math.prod([], start=7) == 7

Examples

import math
print(math.prod([2, 3, 4]))
print(math.prod([], start=7))

Result

24
7

Multiplication folds numeric elements into a single result. The default initial factor 1 gives 2 × 3 × 4 = 24; a keyword-only start of 7 remains 7 for empty input. Multiplying a list by an integer instead repeats its sequence.

Sources