Python sum() Function

❮ Built-in Functions


Example

Add all items in a tuple, and return the result:

a = (1, 2, 3, 4, 5)
x = sum(a)
Try it Yourself »

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)
Try it Yourself »

❮ Built-in Functions

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.