Definition
The sum() function returns a number, the sum of all items in an iterable.
Syntax
sum(iterable, start)
Parameters
Parameter | Description |
---|---|
iterable | Required. The sequence to sum |
start | Optional. A value that is added to the return value |
Examples
# starts at 0 and adds the numbers from the sequence
myNumbers = (1, 2, 3, 4, 5)
result = sum(myNumbers, 0)
print(result)