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, which is the sum of all items in the iterable.

Syntax

sum(iterable, start)

Parameter Value

Parameter Description
iterable Required. The sequence of requirements.
start Optional. Add to the returned value.

More Examples

Example

Start with the number 6 and add all items in the tuple to this number:

a = (1, 2, 3, 4, 5)
x = sum(a, 6)

Run Example