✦ Python Foundations Functions module

Concept 17 · Return Values

Send a result back.
Use it later.

print shows a value, while return lets you store a result and use it in later calculations.

01 Learn02 Try03 Predict

return gives a function result back to the caller.

print shows a value, while return lets you store a result and use it in later calculations.

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

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

The function returns 750, which is stored in total before print displays it.

Change one value or function call, then explain how the result changes.

↳

Keep this in mind: Read the function definition and its calls before predicting the result.

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

total = calculate_total(250, 3)
print(total)
# Change the inputs and use total again

Run the example, then change one value and observe the result.

Python Playground

Loading Python runtime…

Edit the example and run it in your browser.

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

Ask Sloby about this concept

Describe what feels unclear and Sloby will guide your reasoning.

Hi! I'm Sloby. Let's explore this Python concept together.

What will this program print, and why is return useful when a result is needed later?

def add(a, b):
    return a + b

first = add(2, 3)
print(first * 2)
Python AI Tutor · Learn by understanding, not just by running code.