← Go Back

How to Calculate the Average of a Group of Numbers

The statistics standard module provides the mean() function for this.

>>> from statistics import mean
>>> mean([4, 2, 9, 15])

Since statistics was first introduced in Python 3.4, previous versions can simply define the function as follows.

def mean(it):
return sum(it) / len(it)

The argument required by both functions is any iterable object: a list, a tuple, etc.

mean average statistics