✦ Python Foundations Functions module

Concept 17 · Return Values

Send a result back.
Use it later.

Concept 16 showed how an argument gives a function input. Now follow the result as it leaves the function and returns to the code that called it.

01 Learn02 Try03 Predict

Learning as a guest

Learning as a guest? Save your progress!

Create a free account to learn with Sloby AI, check your understanding, and track your progress.

The entire platform is free throughout 2026. Foundations stays free forever.

Send a useful result back to the code that called the function.

A function can receive input, do work, and send a result back. This completes the basic flow: input → function → returned value. The calling code can then decide what to do with that value.

def double(number):
    return number * 2

result = double(4)

In double(4), 4 is the argument. During this call, the parameter number receives 4. The body calculates 4 * 2, and return sends 8 back to the caller. The call double(4) therefore gives the value 8.

Read result = double(4) in two small steps: double(4) → 8, then result = 8. A function call that returns a value can be treated as that value in the surrounding code.

↳

Follow the value through the function: argument → parameter → function body → return value → caller. An argument gives the function input; return sends its result back to the place where the call happened.

Trace one returned value
def calculate_total(price, quantity):
    return price * quantity

total = calculate_total(250, 3)
print(total)

At calculate_total(250, 3), price = 250 and quantity = 3. The body calculates 250 * 3, which is 750. return 750 sends that value back, so total = 750. Finally, print(total) displays 750.

print shows; return sends back
def show_total(price, quantity):
    print(price * quantity)

def calculate_total(price, quantity):
    return price * quantity

print() displays a value for a person to see. That is useful, but it does not by itself give the calculated value back to the rest of the program. return sends the value to the caller, which can save it, print it, or use it in another calculation.

Use a returned value later
result = double(4)
print(result)

print(double(4))

next_result = double(4) + 2

The same returned value can be stored, displayed directly, or used in a later simple expression. Here double(4) gives 8, so next_result receives 10.

return ends this function call
def example():
    print("Before")
    return 10
    print("After")

Python prints Before, then return 10 sends back 10 and ends this call to example(). The later print("After") does not run during that call.

A call can stand for its returned value
answer = double(5) + 1
# double(5) → 10
# answer = 10 + 1
# answer = 11

First replace the call mentally with the value it returns. Then continue reading the caller. This makes function calls easier to trace without treating them as mysterious special syntax.

A practical return-reading checklist

  1. Find the callWhich function is called, and what arguments does this call provide?
  2. Map arguments to parametersDecide which values the parameters represent during this call.
  3. Trace the bodyFollow the calculation or other instructions in the function body.
  4. Find the returned valueWhat expression or value does return send back?
  5. Replace the call mentallyReplace the call with its returned value, then keep reading the caller.

Common beginner mistakes

  • Confusing print() with returnprint() displays a value; return sends a value back to the caller for later program logic.
  • Calculating a value but forgetting to return itIf later code needs the result, the function must return that result instead of only calculating or displaying it.
  • Expecting code after return to runOnce Python executes return for this call, the function call ends and later body lines are not reached.
  • Ignoring a result that is needed laterCalling a function can do its calculation, but save the returned value in a variable when the caller needs to use it later.
  • Thinking return permanently changes an argumentreturn sends a result back from the current call. It does not permanently replace the value that was passed in as an argument.
  • Not asking where the returned value goesLook at the call site: is the result assigned to a variable, printed, or used in another expression?

Python Playground

Loading Python runtime…

Before you run the code, trace the value returned by calculate_total. Then change the inputs, store the result, print it, and use it in one more simple calculation.

return_values.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

Read the function definition and each call before choosing an answer.

def double(number):
    return number * 2

result = double(4)
print(result)
Choose the output
Sloby, the Python AI Tutor mascot

Your learning mentor

Sign in to ask Sloby

Create a free account or sign in to get AI guidance while you learn.

Sign in to check your understanding

Create a free account or sign in to receive AI feedback and save your learning progress.

Python AI Tutor · Learn by understanding, not just by running code.