sum(iterable, /, start=0)

Adds up elements of the specified object and returns the result.

Parameters

  • iterable: An object that supports iteration over its elements. Elements must be numbers, not strings. If the object is empty, the function returns the initial value (start).
  • start=0: The number from which to start summing.

Return Value

sum() returns the sum of start and elements of the given iterable.

Examples

sum([])  # 0
sum([1, 2, 3])  # 6

sum([], 3)  # 3
sum([1, 2], 3)  # 6