statistics.mean() vs statistics.median()
statistics.mean() and statistics.median() are both Python Statistics Module APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. statistics.mean(): Returns the arithmetic mean (average) of numeric data. Its syntax is statistics.mean(data), and it returns float statistics.median(): Returns the median (middle value) of numeric data. Its syntax is statistics.median(data), and it returns float or int Example of statistics.mean(): import statistics
statistics.mean([1, 2, 3, 4, 5]) # 3. Example of statistics.median(): statistics.median([1, 3, 5]) # 3
statistics.median([1, 3, 5, 7]) # 4.0 (average of 3 and 5). Read the full references for statistics.mean() and statistics.median() to see parameters, edge cases, and example code side by side. Other Statistics Module APIs worth comparing: statistics.median_low(), statistics.median_high(), statistics.mode(), statistics.multimode(), statistics.stdev(), statistics.pstdev(). Both belong to the Statistics Module category in the Python Reference documentation.