sum() function in Python List

It is a function in python that returns the Sum of the list. The list must contains numbers only and it returns a integer value.

Syntax:

sum(list, added)
*added– is the value that is added to the sum of the list. By default it is 0.

Don’t know what is min function in Python List? Read: min() function in Python List

Example 1:

# Python program to understand sum() function in list
# www.codewindow.in

s = [2, 8, 10]
x = sum(s)
print(x)

Output:

20

Explanation:

Here the sum of the numbers in the list is 20. Hence it returned 20.

Example 2:

# Python program to understand sum() function in list
# www.codewindow.in

s = [85, 55, 47, 98, 32, 65, 62, 54] 
x = sum(s)
print(x)

Output:

498

Explanation:

Here the sum of all the numbers in the list is 498 . Hence it returned 498.


You Missed

Also Checkout