Chapters
Python114 chapters

ReferenceBuilt-in functions

sum()

Adds up numbers, beginning from start.

Signature

sum(iterable, start=0)

Parameters

NameMeans
iterablenumbers to add
startthe value to begin from

Returns

The total.

Example

Python
print(sum([1, 2, 3]))
print(sum([1, 2], 10))
print(sum(n > 2 for n in [1, 2, 3, 4]))

Output

6
13
2

See also