return Return value
Last updated: 2026-09-22
return Return value
return returns a value to the caller and exits the function; with no expr, returns None.
| Category | Keywords & Statements |
|---|---|
| Kind | Keyword / Statement |
| Python Version | all |
📝 Syntax
return [expression]
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
42 None
🏷️ Related Keywords / Statements
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does the error `SyntaxError: 'return' outside function` mean?
A`return` can only appear inside a function body. Writing it at module top level, in a class body, or outside a function (e.g. in a top-level `if`/`for`) triggers this error. Move the code inside a function.
QWhat does `return` return when no value follows it?
AIt returns `None`. Also, once `return` executes, the function ends immediately and any statements after it are skipped — a useful way to exit early.
QCan `return` return multiple values at once?
AYes. `return a, b` actually returns a tuple `(a, b)`; the caller unpacks it with `x, y = f()` to get both values.