Why a Python Loop Is Slow

Talk it through out loud with your AI coach.

The problem

  • medium
  • Pro

A loop that adds up the squares of fifty million numbers takes several seconds in Python, while the same loop in C takes a fraction of a second. Explain why pure Python loops are slow and what you'd do about it.

What a strong answer covers

  • What the interpreter does on every operation that compiled code doesn't.
  • How Python represents numbers and why that matters here.
  • Measuring before optimising.
  • Ways to move the heavy lifting out of the interpreted loop.

Common mistake: Blaming the global interpreter lock, which has nothing to do with a single-threaded loop's speed.

Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.

Practise it out loud