Finding the average of a list
Here is a Python code snippet for finding the average of a list of numbers:
Tags
Here is a Python code snippet for finding the average of a list of numbers:
Finding the average of a list of numbers in Python
numbers = [1, 2, 3, 4, 5]
average = sum(numbers) / len(numbers)
print(average)
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Python - The Practical Guide</div>
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.