Module 4 · Function return · Lesson 1 of 4
Effects and results: return
A function can do two quite different things. It can have an effect — something visible that happens, like print putting text on the screen. And it can produce a result — a value it hands back to whoever called it. The tool for handing a value back is return.
Here's the key idea: return makes the whole call become that value. After return n * n runs, square(5) is, for all purposes, just 25 — so you can store it, print it, or drop it straight into another expression.
One more thing return does: it ends the function immediately. The moment Python hits a return, it stops and jumps back to the caller — any lines below it in the function are skipped. That makes it perfect for handling special cases early.
So a function can act, return a value, or both. But what does a function give back when it has no return at all? Python has a special answer for that — next.