How to find Average in Python

In this article, we will see how to find average of list in Python.
An average is a value that represents a whole set of data items or elements. Average can be found using the following formula:
Average = summation of numbers/total count
Method 1:
The statistics module
contains an in-built function to calculate the mean or average of numbers. The statistics.mean() function
is used to calculate the mean/average of input values or data set. The mean() function accepts the list, tuple or data-set containing numeric values as a parameter and returns the average of the data-items.
>>> from statistics import mean >>> li = [11, 54, 76, 33, 13, 87] >>> li_avg = mean(li) >>> print(li_avg) 45.666666666666664
Method 2:
Using sum() and len() function. Python sum()
function can also be used to find the average of data values in Python list. The len()
function is used to calculate the length of the list i.e. the count of data items present in the list.
>>> li = [11, 54, 76, 33, 13, 87] >>> li_sum = sum(li) >>> li_len = len(li) >>> li_avg = li_sum / li_len >>> print(li_avg) 45.666666666666664