Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

Describing Data: Mean, Median & Mode

12 min 30 XP
Study loop Read Predict Run Tweak Prove Review
Lesson 1 of 5 · View course roadmap
Step 1

Learn the idea

Before charts, before machine learning, analysis starts with three questions — and Python's built-in statistics module answers all of them:

  • mean(data) — the average. Honest for balanced data, easily dragged around by one extreme value
  • median(data) — the middle value. Robust: one billionaire in the room changes the mean salary wildly, the median barely
  • mode(data) — the most common value. The only one that also works on words and categories

Knowing which to reach for is the analysis skill: report medians for incomes and house prices, means for balanced measurements, modes for "what's most popular?".

Where you'll use this

'Median household income', 'average response time', 'most common error' — every metrics dashboard and news statistic is these three functions. Choosing mean vs median honestly is half of data literacy.

Common mistakes

  • Reporting the mean of skewed data (salaries, house prices, response times) — one outlier misleads everyone downstream.
  • Calling mode() on data with no repeats — in older Pythons it raised; modern statistics.mode returns the first value, which may surprise you.
  • Doing sum(x)/len(x) on an empty list → ZeroDivisionError. Guard empty datasets before describing them.

Pro tip

statistics.quantiles(data, n=4) gives quartiles — the p25/p50/p75 shape of your data. Engineers report p95 latency, not the average, for exactly the outlier reasons above.

Step 2

Try it yourself

Blank · autosaved

The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.

PYexample.py
+ Enter to run
Output appears here…
Step 3

Pass the challenge +30 XP

Blank · autosaved

For scores = [72, 88, 95, 64, 88, 79] print three lines: the mean shown with 1 decimal place, the median, and the mode.

Target output
81.0
83.5
88
PYchallenge.py
Run your code to check it…
Step 4

Check your understanding

1. House prices in a street: eight around €300k, one at €5M. Which average should you report?
2. Which statistic works on non-numeric data like ["red", "blue", "red"]?
Last step

Your notes (saved on this device)

Tip: use and to move between lessons, K to search everything.

Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path