Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python sum() Function

Python sum() Function

Python built-in function Python built-in function


Description

sum() The method computes the sum of a sequence.

Syntax

The following is the syntax of the sum() method:


sum(iterable[, start])

Parameters

Return Value

Returns the computed result.


Example

The following examples demonstrate the use of the sum function:

sum

(

[

0

,

1

,

2

]

)

3

sum

(

(

2

,

3

,

4

)

,

1

)

Add 1 after summing the tuple

10

sum

(

[

0

,

1

,

2

,

3

,

4

]

,

2

)

Add 2 after summing the list

12

Python built-in function Python built-in function