How to Find the Average of a List in Python

By Mike Wallace

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.

Things You'll Need

  • Python 3.2 (see Resources)

Step 1

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

Step 2

Declare a list and fill it with values. One way is to write something like this:listValues = [ 32, 81, 43, 16, 72, 99, 14, 50]

Step 3

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

Step 4

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

Step 5

Find the average value in the list by dividing the sum by the length, like this:listAverage = listSum / listLength

Step 6

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

Step 7

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