Find AVERAGE of a List in Python with Example

The formula to calculate average is done by calculating the sum of the numbers in the list divided by the count of numbers in the list.

The average of a list can be done in many ways listed below:

  • Python Average by using the loop
  • By using sum() and len() built-in functions from python
  • Using mean() function to calculate the average from the statistics module.
  • Using mean() from numpy library

In this Python tutorial, you will learn:

Python Average via Loop

In this example, we have initialized the variable sum_num to zero and used for loop. The for-loop will loop through the elements present in the list, and each number is added and saved inside the sum_num variable. The average is calculated by using the sum_num divided by the count of the numbers in the list using len() built-in function.

top
X
Welcome to Our Website
Welcome to WPBot
wpChatIcon