Analyzing some sales data for a client in New York, I needed to quickly calculate the average (mean) of a list of numbers in Python.
It seemed like a simple task, but I realized there are several ways to do it, some faster, some more Pythonic, and others that give you more control.
In this tutorial, I’ll walk you through four simple methods to find the mean of a list in Python. These are practical, real-world approaches I’ve used during my 10+ years as a Python developer working with analytics and data science projects.
What Is the Mean in Python?
Before we start coding, let’s quickly understand what the mean actually is.
In statistics, the mean (or average) is the sum of all numbers divided by how many of numbers there are. It’s one of the most common ways to measure the “central tendency” of data.
For example, if you have a list of monthly sales figures like [1000, 1200, 900, 1100, 1300], the mean would tell you the typical monthly sales for that period.
Now, let’s see how to calculate this using Python.
Method 1 – Use Python’s Built-in sum() and len() Functions
This is the simplest way to find the mean of a list in Python. I often use this method when I’m working on small datasets or scripts that don’t require importing external libraries.
Here’s how you can do it:
# List of daily sales in USD
sales = [250, 300, 275, 400, 325, 350, 375]
# Calculate mean using sum() and len()
mean_sales = sum(sales) / len(sales)
print("Average daily sales:", mean_sales)I executed the above example code and added the screenshot below.

This code adds up all the numbers in the list using sum() and divides by the number of items using len(). When you run it, you’ll get the average daily sales, a quick and efficient way to find the mean in Python without any extra packages.
Method 2 – Use the statistics.mean() Function in Python
Python’s statistics module makes it even easier to calculate the mean. I use this method when I want my code to be more readable and explicitly clear that I’m calculating a mean value.
Here’s how it works:
import statistics
temperatures = [68, 70, 72, 71, 69, 73, 70]
# Calculate mean temperature
mean_temp = statistics.mean(temperatures)
print("Average temperature (°F):", mean_temp)I executed the above example code and added the screenshot below.

The statistics.mean() function does all the heavy lifting for you. It automatically handles the summing and counting internally, making your code cleaner and easier to understand, especially when working with other developers or analysts.
Method 3 – Use NumPy’s mean() Function (Best for Large Data)
When you’re working with large datasets, for example, analyzing thousands of transactions or sensor readings, the NumPy library is your best friend.
NumPy is optimized for numerical operations and can handle large lists or arrays much faster than plain Python.
Here’s a practical example:
import numpy as np
# List of weekly customer ratings
ratings = [4.5, 4.7, 4.8, 4.2, 4.9, 4.6, 4.8]
# Calculate mean rating using NumPy
mean_rating = np.mean(ratings)
print("Average customer rating:", mean_rating)I executed the above example code and added the screenshot below.

NumPy’s mean() function is extremely efficient and widely used in data science and machine learning. I often use this method when working with Pandas DataFrames or large numerical arrays because it integrates seamlessly with other scientific computing tools in Python.
Method 4 – Calculate the Mean Manually Using a Loop
Sometimes, when teaching Python to beginners or debugging a piece of code, I prefer to calculate the mean manually using a loop. This helps you understand what’s happening behind the scenes.
Here’s how you can do it step by step:
# List of exam scores
scores = [88, 92, 79, 85, 94, 90, 87]
# Initialize total
total = 0
# Loop through the list and add each score
for score in scores:
total += score
# Calculate the mean
mean_score = total / len(scores)
print("Average exam score:", mean_score)I executed the above example code and added the screenshot below.

This method is not the most efficient, but it’s great for learning. It shows exactly how Python adds up the numbers and divides by the count, giving you a better understanding of how averages work under the hood.
Bonus Tip – Handle Empty Lists or Invalid Data in Python
One common issue I’ve seen beginners face is trying to find the mean of an empty list. If you try to divide by zero, Python will throw a ZeroDivisionError. So, it’s good practice to handle that gracefully.
Here’s an example:
# Example: Handle empty list when finding mean
data = []
if len(data) == 0:
print("The list is empty. Cannot calculate mean.")
else:
mean_value = sum(data) / len(data)
print("Mean value:", mean_value)This small check ensures your Python program doesn’t crash unexpectedly. In real-world projects, especially when dealing with user input or raw data, these checks can save you from bugs and errors.
Real-World Example – Find the Mean of Monthly Sales in Python
Let’s put everything together with a practical example. Suppose you’re analyzing monthly sales data for a small business in California. You want to find the average monthly revenue to understand business performance.
Here’s how you can do it:
import statistics
# Monthly sales data (in USD)
monthly_sales = [12000, 15000, 13500, 16000, 14500, 15500, 17000, 16500, 15000, 17500, 18000, 19000]
# Calculate average monthly sales
average_sales = statistics.mean(monthly_sales)
print("Average Monthly Sales: $", round(average_sales, 2))This gives you a clear view of your average monthly performance. You can even extend this by comparing yearly averages or visualizing trends using Matplotlib or Pandas.
When to Use Each Method in Python
Here’s a quick summary of when to use each approach:
| Method | Best For | Requires External Library |
|---|---|---|
sum() + len() | Small lists, quick calculations | ❌ No |
statistics.mean() | Readable code, built-in reliability | ❌ No |
numpy.mean() | Large datasets, data science projects | ✅ Yes |
| Manual Loop | Learning, debugging, or custom logic | ❌ No |
Each method has its place depending on what you’re working on. If you’re writing a quick script, go with sum() and len(). But if you’re analyzing thousands of data points, NumPy is the way to go.
Conclusion
Finding the mean of a list in Python is one of the most common tasks in data analysis, and luckily, Python makes it incredibly easy.
Whether you’re using built-in functions, the statistics module, or NumPy, each method gives you flexibility depending on your project’s needs.
I personally prefer statistics.mean() for small, clean scripts and numpy.mean() when working with large datasets or machine learning workflows.
You may also like to read:
- Count Occurrences in Python List
- Remove Multiple Items From a List in Python
- Remove Brackets From List in Python
- ValueError: Could Not Convert String to Float 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.