Find the Average of a List in Python

  • Post category:List

Finding the average of a list in Python can be achieved by summing all the elements and dividing by the length of the list. Here are two examples:

Example 1:

numbers = [1, 2, 3, 4, 5]
average = sum(numbers) / len(numbers)
print(f"The average of the list is: {average}")

Output:

The average of the list is: 3.0

Example 2:

grades = [85, 90, 92, 88, 95]
average = sum(grades) / len(grades)
print(f"The average grade is: {average}")

Output:

The average grade is: 90.0