sum

Full name
sum
Library
Built-in
Syntax

sum(iterable[, start])

Description

The sum function sums the start value and the values contained in the iterator included as the first argument, returning the total. By default, start takes the value 0.

Parameters
  • iterable: Iterable object whose elements we want to add.
  • start: (Optional) additional amount to add. If this argument is not specified, it is considered the default value of zero.
Result

The sum function returns an integer, real or complex number, depending on the type of the elements in the iterable.

Examples

In this first example we have an iterator that contains integers and we do not specify the start argument. The function simply returns the sum of the elements of the iterator as an integer:

Sum function. Example of use

Here, the list contains a real number and we set the start argument to 10. The function adds 10 to the values in the list and returns a real number:

Sum function. Example of use

In this third example, the list includes a complex number, and the result of the function is also returned as a complex number:

Sum function. Example of use
Submitted by admin on Wed, 01/30/2019 - 15:31