Python sum() function

Published February 17, 2022

In programming, you may need to find the sum of the numbers in a specified list. To do so,  we use the python sum() built-in function, which sums up the numbers in a given list.

Syntax of the sum()
The sum() method is written as follows:

Sum(iterable or list of  numbers in a list)


Example

In this example, we are going to find the sum of  the numbers in a list.

my_list = [1,2,3,4,5,6,7,8,9,10]
Sum_my_list = sum(my_list)
print(Sum_my_list)


Output
The sum of the numbers in the list is 25

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

259 Views