sum
Add up the items of an iterable.
Python 3.13
sum(iterable, start=0)- =default value
- iterable
- The numbers to add up.Iterable
- start
- The value the items are added to, 0 by default.int | floatOptional
Return value
The sum of start and all the items; start for an empty iterable.
Examples
Sum of list numbers
Python 3.13
print(sum([1, 2, 3, 4, 5]))15
Sum with a start value
Python 3.13
print(sum([0.5, 1.5], start=10))12.0
Details
Strings cannot be added up this way; use str.join for them.
