Return the numeric sum of an iterable, optionally starting from start. A generator expression can omit its own parentheses only when it is the sole argument of a function or method call; extra arguments or a trailing comma require parentheses around the generator.
Syntax
sum(iterable, /, start=0)Parameters
Returns
Number — Total numeric value.Example
# Sum generated values
values = [1, 2, 3]
total = sum(value * 2 for value in values)
with_start = sum((value * 2 for value in values), start=10)
text(str(total))
text(str(with_start))