Python sum() Function

Sums all the items in an iterator

Syntax

Python
sum(iterator)

Parameters

ParameterDescription
iterator Required. An iterator containing the items to be summed.

Example

Python
total = sum(range(1, 100))
print('The sum of numbers from 1 to 100 is: ', total)

Output

The sum of numbers from 1 to 100 is: 4950