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]

Example: Calculate Mean of List Using mean() Function of statistics Module

import statistics                           # Load statistics
print(statistics.mean(x))                   # Get mean of list
# 4.166666666666667

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top