Python | sum method
Start your free 7-days trial now!
sum(~) method adds the items of an iterable from left to right and returns the total.
The iterable whose items are to be added. The elements of the iterable should be numbers.
This value to add to the total. Default is 0.
Returns the total sum of items of the provided iterable plus the start if applicable.
To return the sum of elements in the list
numbers = [12, 3, 6, 4, 8]sum(numbers)33
To specify a start of
10 when summing the
numbers = [12, 3, 6, 4, 8]sum(numbers,10)43
10 is added to the sum of the elements in
numbers (33) giving us a return value of