← Go Back
Since
The argument required by both functions is any iterable object: a list, a tuple, etc.
How to Calculate the Average of a Group of Numbers
Thestatistics
standard module provides the mean()
function for this.>>> from statistics import mean
>>> mean([4, 2, 9, 15])
7.5
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.