Skip to content

How to calculate sum of a list in Python?

The following Python code demonstrates the working of sum() function which is used to sum all elements in a list.

numbers = [10,22,30,40,50]
# Call sum function by passing list
Sum = sum(numbers) 

# We can also specify a numnber as second param to sum function which will be added to the list's sum.
Sum = sum(numbers, 10) 
See also  Python code snippet - How to make multiple box plots?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.