![]() |
VOOZH | about |
The mean() function from Python’s statistics module is used to calculate the arithmetic average of numeric values. It adds all the values and divides the sum by the total number of values. This function is commonly used to find the central value of data.
Example: This example calculates the average of numbers in a list using mean().
25
Explanation:
statistics.mean(data)
Example 1: This example finds the average marks of students stored in a list. It helps understand overall student performance.
Mean: 86.6
Example 2: This example calculates the mean of fraction values using the Fraction class. It shows that mean() returns the result as a fraction when all inputs are fractions.
Mean: 25/36
Explanation:
Example 3: This example tries to calculate the mean of string values. Since mean() works only with numeric values, it raises a TypeError.
Output
TypeError: can't convert type 'str' to numerator/denominator