Categories
Python Answers

How to find the average of a list with Python?

Spread the love

Sometimes, we want to find the average of a list with Python.

In this article, we’ll look at how to find the average of a list with Python.

How to find the average of a list with Python?

To find the average of a list with Python, we can use the statistics.mean method.

For instance, we write:

import statistics

l = [15, 18, 2, 36, 12, 78, 5, 6, 9]

avg = statistics.mean(l)
print(avg)

We call statistics.mean with l to calculate the average of the entries in l and return it.

Therefore, avg is 20.11111111111111.

Conclusion

To find the average of a list with Python, we can use the statistics.mean method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *