While working on a data analytics project for a U.S.-based retail client, I needed to calculate the total daily sales from a list of transactions. Each value represented the sales amount for a day, stored neatly in a Python list.
At first, I thought of using the built-in sum() function, but then I realized there are multiple ways to sum elements in a list in Python, some more flexible and efficient depending on the situation.
In this tutorial, I’ll show you four simple and practical methods to sum elements in a list in Python. These methods range from using a for loop, the sum() function, list comprehension, and even the reduce() function.
Sum Elements in a List in Python
Multiple methods exist to sum elements in a list in Python, such as for loop, sum(), list comprehension, and reduce() methods. Let’s see each technique one by one.
Method 1: Use For Loop in Python
The most obvious way to add numbers stored in a list is to use a for-loop. The following code fragment visits each list element in order and totals the sum of its elements.
For example, look at the logic of the code below.
# List of daily sales figures
daily_sales = [250, 450, 300, 400, 500, 600, 350]
# Initialize total_sales to 0
total_sales = 0
# Iterate over each sale in the daily_sales list
for sale in daily_sales:
# Add the current sale to the running total
total_sales += sale
# Print the total sales for the week using an f-string
print(f"Total sales for the week: ${total_sales}")You can refer to the screenshot below to see the output.

From the output, you can see that all the daily sales in the list are added together.
Method 2: Use sum() Method in Python
A Python built-in function: sum(). Another way to shorten the syntax for summing elements in the list is by using the built-in function.
For example, run the code below to sum the list.
# List of daily sales figures
daily_sales = [250, 450, 300, 400, 500, 600, 350]
# Calculate the total sales by summing up all values in the daily_sales list
total_sales = sum(daily_sales)
# Print the total sales for the week using an f-string
print(f"Total sales for the week: ${total_sales}")You can refer to the screenshot below to see the output.

Method 3: Use Python List Comprehension
A list comprehension is a more concise way to create and combine lists with the sum() function in more complex cases.
For example, run the code below to understand how to sum list elements using list comprehension, where you need to calculate the sales to be greater than 300 dollars.
# List of daily sales figures
daily_sales = [250, 450, 300, 400, 500, 600, 350]
# Calculate the total sales for days with sales over $300
# using a list comprehension and the sum() function
total_sales = sum([sale for sale in daily_sales if sale > 300])
# Print the total sales for days with sales over $300 using an f-string
print(f"Total sales for days with sales over $300: ${total_sales}")You can refer to the screenshot below to see the output.

Method 4: Use Python’s reduce() Method
The general form of reduce() from the functools module is a rolling computation on successive pairs of elements from a sequence. This style doesn’t occur often, but it can sometimes be quite helpful.
Let’s see with an example.
# Import the reduce function from the functools module
from functools import reduce
# List of daily expenditures
expenditures = [1200, 1500, 1100, 1400, 1700, 1600, 1300]
# Calculate the total expenditure for the month using reduce and a lambda function
total_expenditure = reduce(lambda x, y: x + y, expenditures)
# Print the total expenditure for the month using an f-string
print(f"Total expenditure for the month: ${total_expenditure}")You can refer to the screenshot below to see the output.

While there are multiple ways to sum elements in a list in Python, the best method depends on your use case.
If you’re learning or working with small datasets, the for loop or built-in sum() function is perfect. For large-scale data or performance-critical tasks, the reduce() function is the way to go.
You may like to read:
- Save a Matplotlib Graph as a PDF in Python
- Save Matplotlib Subplots to PDF in Python
- Save Multiple Pages to a PDF in Matplotlib
- Save Matplotlib Table as PDF in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.