For Python 3.8+, use statistics.fmean for numerical stability with floats. (Fast.)

For Python 3.4+, use statistics.mean for numerical stability with floats. (Slower.)

xs = [15, 18, 2, 36, 12, 78, 5, 6, 9]

import statistics
statistics.mean(xs)  # = 20.11111111111111

For older versions of Python 3, use

sum(xs) / len(xs)

For Python 2, convert len to a float to get float division:

sum(xs) / float(len(xs))
Answer from Herms on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-average-list-python
Find average of a list in python - GeeksforGeeks
Note: If the list is empty, sum(a) / len(a) raises a ZeroDivisionError because len(a) is 0. Check whether the list contains elements before calculating the average. Comment · Python Fundamentals · Introduction1 min read · Input & Output2 ...
Published: April 27, 2025
🌐
W3Schools
w3schools.com › python › ref_stat_mean.asp
Python statistics.mean() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training · ❮ Statistic Methods · Calculate the average of the given data: # Import statistics Library import statistics # Calculate average values print(statistics.mean([1, 3, 5, 7, 9, 11, 13])) print(statistics.mean([1, 3, 5, 7, 9, 11])) print(statistics.mean([-11, 5.5, -3.4, 7.1, -9, 22])) Try it Yourself » ·
🌐
SW Hosting
swhosting.com › en › comunidad › manual › the-5-ways-to-find-the-average-of-a-list-in-python
The 5 ways to find the average of a list in Python
October 2, 2025 - Once this is clarified, we will present 5 ways to find it. The sum() function takes a list of numbers as an argument and returns the sum of all of them. On the other hand, the len() function returns the number of elements in a list.
🌐
Guru99
guru99.com › home › python › how to find average of list in python
How to Find Average of List in Python
July 11, 2026 - The formula to calculate average in Python is done by calculating the sum of the numbers in the list divided by the count of numbers in the list.
🌐
PythonForBeginners.com
pythonforbeginners.com › home › calculate average in python
Calculate Average in Python - PythonForBeginners.com
December 16, 2021 - The list of numbers is: [1, 2, 34, 56, 7, 23, 23, 12, 1, 2, 3, 34, 56] The average of all the numbers is: 19.53846153846154 · Instead of using for loops, we can use built-in functions in python to calculate the average of elements in a given list.
🌐
Career Karma
careerkarma.com › blog › python › python average: a step-by-step guide
Python Average: A Step-by-Step Guide | Career Karma
December 1, 2023 - The formula for calculating the average of a list of values is the sum of all terms divided by the number of those terms. We can use the Python sum() and len() values to calculate the average of the numbers in a list.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
Find elsewhere
🌐
Replit
replit.com › home › discover › how to find the average in python
How to find the average in Python | Replit
April 14, 2026 - Learn how to find the average in Python. Explore different methods, real-world applications, and common errors to debug your code effectively.
🌐
DigitalOcean
digitalocean.com › community › tutorials › average-of-list-in-python
Calculate Average of List in Python: 5 Methods | DigitalOcean
Find the average of a Python list using statistics.mean(), sum(), NumPy, and more. Compare methods with examples and performance considerations.
🌐
Centron
centron.de › home › tutorials › calculating averages made easy: an overview of 5 python methods
Calculating Averages Made Easy: An Overview of 5 – centron
May 1, 2024 - The simplest method to calculate the average of a list is to use the statistics.mean() function. This function is available in Python 3 within the "statistics" module and accepts a list, tuple, or dataset containing numeric values as input.
🌐
FavTutor
favtutor.com › blogs › average-list-python
Find Average of a List in Python: 5 Simple Methods (with Codes)
November 15, 2023 - Once we have this list of numbers, we can add up each one of them using the sum() method that is already built into python. The average can then be obtained by dividing the total by the number of elements in the list.
🌐
Python.org
discuss.python.org › ideas
An average function builtin? - Ideas - Discussions on Python.org
September 4, 2024 - Originally started on github: math.average function proposal · Issue #123658 · python/cpython · GitHub I would like to propose a new builtin named avg that averages an itterable. I have made the code for this, however I…
🌐
Reddit
reddit.com › r/learnpython › help please "learning how to calculate the average"
r/learnpython on Reddit: help please "learning how to calculate the average"
June 15, 2023 -
with inputs 10 and 5, my avg outcome is giving me 8. any help

# Initialize the total count variable to 0

total_books = 0

Prompt the user for the first input

book_count = input("Enter the number of books read (or 0 to stop): ")

Continue the loop until the sentinel value "0" is entered

while book_count != "0": # Convert the input to an integer and add it to the total count total_books += int(book_count)

# Prompt the user for the next input
book_count = input("Enter the number of books read (or 0 to stop): ")

Display the total number of books read

print("The total number of books read is:", total_books)

Creating the average using total_books

n = total_books total_numbers = n sum = 0 while n >= 0: sum += n n -= 1

average = sum / total_numbers print(("Average = %f") % average)

*outcome

Enter the number of books read (or 0 to stop): 10

Enter the number of books read (or 0 to stop): 5 Enter the number of books read (or 0 to stop): 0 The total number of books read is: 15 Average = 8.000000

🌐
Medium
medium.com › @ArunaKale › how-to-calculate-the-average-of-list-elements-from-user-input-in-python-d6b677519362
Step-by-Step Python Tutorial: Calculate Average from Hardcoded Values and User Input | by Aruna | Medium
October 29, 2025 - Before jumping into the Python code, let’s first understand what an average means. The average (also called the mean) is a value that represents the central point of a group of numbers. It tells us what the numbers would be if they were all the same and had the same total.
🌐
Educative
educative.io › answers › how-to-take-the-average-of-a-list-in-python
How to take the average of a list in Python
Python offers multiple ways to calculate the average of a list. The average is computed by dividing the sum of all numbers in a list by length.
🌐
Analytics Vidhya
analyticsvidhya.com › home › 5 ways of finding the average of a list in python
5 Ways of Finding the Average of a List in Python
May 19, 2025 - One of Python’s simplest methods for finding a list’s average is a for loop. This method involves iterating over each element in the list, summing up the values, and then dividing the sum by the length of the list.
🌐
Quickprogrammingtips
quickprogrammingtips.com › python › how-to-calculate-average-of-numbers-in-python.html
How to Calculate Average of Numbers in Python
The average or arithmetic mean of a collection of numbers is calculated by adding the numbers and then dividing it with the number of numbers in the collection.
🌐
Vultr Docs
docs.vultr.com › python › third party › numpy › average()
Python Numpy average() - Compute Mean Value
November 11, 2024 - The average() function from the NumPy library is essential for computing the mean value of data elements in an array or along a specific axis of a multidimensional array.
🌐
Scaler
scaler.com › home › topics › program to find average of list in python
Program to Find Average of List in Python - Scaler Topics
April 13, 2024 - The mean() method can be used to directly calculate the average of a list without using any other function. ... Here, we have made use of the in-built mean() function. This function does all the work for us, we just have to pass the list. This method will calculate the sum of all the elements ...