Python sum() Function
Example
Add all items in a tuple, and return the result:
a = (1, 2, 3, 4, 5)
x = sum(a)
Run example »
Definition and Usage
The sum()
function returns a number, the sum
of all items in an iterable.
Syntax
sum(iterable,
start)
Parameter Values
Parameter | Description |
---|---|
iterable | Required. The sequence to sum |
start | Optional. A value that is added to the return value |
More Examples
Example
Start with the number 7, and add all the items in a tuple to this number:
a = (1, 2, 3, 4, 5)
x = sum(a, 7)
Run example »