24-Nov-2022
.
Admin
Hi Dev,
This article is focused on find the average value of a list in python. We will look at example of how to calculate average of a list in python. We will look at example of how to find the average value of a list in python. you will learn python count average of list.
There are many ways to find an average list value in python. I will give you the following three examples to calculate an average of a list in python.
so let's see following examples with output:
Example 1: Sum of List divide by length of List
main.py
myList = [10, 5, 23, 25, 14, 80, 71]
# Find Average from List
avg = sum(myList)/len(myList)
print(round(avg,2))
Output:
32.57
Example 2: using statistics Module
main.py
from statistics import mean
myList = [10, 5, 23, 25, 14, 80, 71]
# Find Average from List
avg = mean(myList)
print(round(avg,2))
Output:
32.57
Example 3: using numpy library
main.py
from numpy import mean
myList = [10, 5, 23, 25, 14, 80, 71]
# Find Average from List
avg = mean(myList)
print(round(avg,2))
Output:
32.57
#Python