Next / Previous / Contents / TCC Help System / NM Tech homepage

20.41. sum(): Total the elements of a sequence

This function, applied to an iterable S, returns the sum of its elements. There are two general forms:

sum(S)
sum(S, I)

In the second form, the summing process starts with the initial value I. Examples:

>>> L=[1,2,3,4]
>>> sum(L)
10
>>> sum(L,1000)
1010
>>> sum((), 1000)
1000