Python Return Values & Data Flow
Printing a result just splashes it on the screen for a human to read. Returning a result hands the computed value back to your program so other parts of your code can store it, do math with it, or pass it into other functions.
"Calling print() inside a function is like a chef shouting the order name in the kitchen. Using return is like the chef placing the prepared meal on your tray so you can eat it or take it home."
Deep Dive: How It Works
The return statement terminates the function immediately and passes the specified value back to the caller.
Assigning return values: result = square(5) captures the returned 25 and stores it in the result variable.
Functions without an explicit return statement automatically return None when they finish executing.
Returning multiple values: Python lets you return multiple comma-separated values (e.g. return width, height), which are packed into a tuple.
Syntax Blueprint
def add(a, b):
return a + b
total = add(10, 20) # total is 30return immediately exits the function and delivers the result value to the caller.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Putting code after a return statementWhy it happens: return exits the function instantly. Code below it becomes unreachable dead code.
How to fix: Ensure return is the final action of your logical branch.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Write a function that returns a value
Define a function square(n) that returns n * n.
Store the result of square(9) in a variable result and print result.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.