statistics.mean() Function in Python – How to Apply (Example Code)
In this tutorial you’ll learn how to apply the mean function of the statistics module in the Python programming language.
Creation of Example Data
x = [1, 4, 7, 3, 5, 7, 1, 2, 8, 4, 1, 7] # Constructing a list in Python print(x) # Displaying the example list # [1, 4, 7, 3, 5, 7, 1, 2, 8, 4, 1, 7] |
x = [1, 4, 7, 3, 5, 7, 1, 2, 8, 4, 1, 7] # Constructing a list in Python print(x) # Displaying the example list # [1, 4, 7, 3, 5, 7, 1, 2, 8, 4, 1, 7]
Example: Calculate Mean of List Using mean() Function of statistics Module
import statistics # Load statistics |
import statistics # Load statistics
print(statistics.mean(x)) # Get mean of list # 4.166666666666667 |
print(statistics.mean(x)) # Get mean of list # 4.166666666666667