find the average of a list of numbers in python

To find the average of a list of numbers in Python, you can use the following code:

main.py
my_list = [1, 2, 3, 4, 5]
average = sum(my_list) / len(my_list)
print(average)
79 chars
4 lines

In this example, we have a list of numbers called my_list. We use the sum() function to add up all the numbers in the list, and then divide by the length of the list using the len() function. This gives us the average of the list, which we store in the variable average. Finally, we print the value of average.

related categories

gistlibby LogSnag