How to Find the Average of a List in Python

The Python programming language has many built-in functions that simplify certain programming tasks. For example, finding the average of values stored in a list is made easy by the built-in functions sum() and len(). These allow you to find out the sum of all the values and the total number of items in a list. This is all you need to know to find the average value.

Step

Open the IDLE text editor in "Program Files" (or "Applications" for Macintosh), in the Python directory. A blank source code file opens.

Step

Declare a list and fill it with values. One way is to write something like this:

Step

listValues = [ 32, 81, 43, 16, 72, 99, 14, 50]

Step

Find the sum of all the values in the list using the sum() function. You can store the sum in a variable like this:

Step

listSum = sum(listValues)

Step

Find the length of the list using the len() function. You can store the length in a variable like this:

Step

listLength = len(listValues)

Step

Find the average value in the list by dividing the sum by the length, like this:

Step

listAverage = listSum / listLength

Step

Print the average value using the print() function like this:

Step

print(listAverage)

Step

Run the program by pressing the "F5" key. The program output looks like this:

Step

50.875