Finding the average of a list

Here is a Python code snippet for finding the average of a list of numbers:

numbers = [1, 2, 3, 4, 5]

average = sum(numbers) / len(numbers)

print(average)

Watch a course Python - The Practical Guide

This code defines a list of numbers, then calculates the average by dividing the sum of the numbers in the list by the number of elements in the list. The sum() function adds up all the elements in a list and the len() function returns the number of elements in a list.