Return Values in Python Functions
A return value is the result a function sends back after it runs. Understanding this is an important step in learning how Python functions work.
The return statement lets a function give data back to the code that called it. You can then store that value, print it, compare it, or use it in another calculation.
If a function does not use return, Python gives back None instead.
def add(a, b):
return a + b
result = add(2, 3)
print(result)
Output:
5
Use return when a function should send a value back. Without return, the function gives back None.
What a return value is
A return value is the result a function sends back.
Here is the basic idea:
- A function runs some code
- It reaches a
returnstatement - Python sends that value back to the caller
- The function stops running at that point
For example:
def greet(name):
return "Hello, " + name
message = greet("Maya")
print(message)
Output:
Hello, Maya
In this example:
greet("Maya")calls the function- The function returns
"Hello, Maya" - That returned value is stored in
message
If you are new to functions, it may help to read Python functions explained first.
Why return values matter
Return values are useful because they make functions more flexible.
They help you:
- Use the result of one function in another part of your program
- Write reusable functions
- Separate calculation from display
- Test your code more easily
For example, this function is reusable because it returns a result instead of printing it directly:
def square(number):
return number * number
result1 = square(4)
result2 = square(10)
print(result1)
print(result2)
Output:
16
100
Because the function returns a value, you can use it in many different places.
Basic return statement example
A simple example is a function that adds two numbers and returns the answer.
def add(a, b):
return a + b
answer = add(7, 5)
print(answer)
Output:
12
What matters here:
aandbare the input valuesreturn a + bsends the answer backanswer = add(7, 5)saves the returned value
This is different from just printing the result. The value is sent back to the caller, so it can be reused later.
If function inputs still feel unclear, see function parameters and arguments in Python.
return vs print
Beginners often mix up return and print, but they do different jobs.
print()displays a value on the screenreturnsends a value back to the code that called the function
Here is a comparison:
def print_sum(a, b):
print(a + b)
def return_sum(a, b):
return a + b
x = print_sum(2, 3)
y = return_sum(2, 3)
print("x:", x)
print("y:", y)
Output:
5
x: None
y: 5
Why this happens:
print_sum(2, 3)displays5, but it does not return anything- Because it has no
return, Python gives backNone return_sum(2, 3)returns5, soystores that value
A function can print and return, but they are not the same thing. This confusion often causes bugs.
If you want a deeper look at printing, see Python print() function explained.
What happens when a function returns nothing
If a function has no return statement, Python returns None.
Example:
def say_hello():
print("Hello")
result = say_hello()
print(result)
Output:
Hello
None
The function prints "Hello", but it does not return a useful value.
A bare return also returns None:
def do_nothing():
return
result = do_nothing()
print(result)
Output:
None
This matters because None is a special value. If you try to use it like a normal number, string, or list, you may get errors.
Returning multiple values
Python can return more than one value by separating them with commas.
def divide_and_remainder(a, b):
return a // b, a % b
result = divide_and_remainder(10, 3)
print(result)
Output:
(3, 1)
Python packs these values into a tuple.
You can also unpack them into separate variables:
def divide_and_remainder(a, b):
return a // b, a % b
quotient, remainder = divide_and_remainder(10, 3)
print("Quotient:", quotient)
print("Remainder:", remainder)
Output:
Quotient: 3
Remainder: 1
This is a simple and common Python pattern.
Using returned values in expressions
A returned value behaves like a normal value.
You can:
- Store it in a variable
- Print it
- Compare it
- Pass it to another function
- Use it in expressions
Example:
def double(n):
return n * 2
def add_three(n):
return n + 3
result = add_three(double(4))
print(result)
Output:
11
What happens step by step:
double(4)returns8add_three(8)returns11print(result)displays11
You can also compare a returned value:
def is_even(number):
return number % 2 == 0
print(is_even(6))
print(is_even(7))
Output:
True
False
This is one reason return values are so useful. They let small functions work together.
If you want practice building simple functions like these, see how to create a simple function in Python.
Common beginner mistakes
Here are some common mistakes beginners make with return values.
Forgetting to write return
The function calculates a value, but never sends it back.
def add(a, b):
a + b
result = add(2, 3)
print(result)
Output:
None
Fix it by returning the value:
def add(a, b):
return a + b
Using print when you need return
This is a very common problem.
def add(a, b):
print(a + b)
result = add(2, 3)
print("Result:", result)
Output:
5
Result: None
The function prints the answer, but does not return it.
Writing code after return and expecting it to run
Once Python reaches return, the function stops immediately.
def example():
return "done"
print("This will not run")
print(example())
Output:
done
The print("This will not run") line is never reached.
Trying to use a function result when the function returns None
This often leads to confusing errors.
def show_name():
print("Ana")
name = show_name()
print(name.upper())
This causes an error because name is None, and None does not have an upper() method.
To debug this kind of problem, try checking what the function really returns:
print(my_function(2, 3))
result = my_function(2, 3); print(result)
print(type(my_function(2, 3)))
If your function returns None when you expected something else, check whether you forgot to use return.
A related problem is explained in TypeError: 'NoneType' object is not iterable.
FAQ
What does return do in Python?
It ends a function and sends a value back to the code that called it.
What happens if a function has no return statement?
Python returns None automatically.
Is print the same as return?
No. print shows something on the screen. return gives a value back.
Can a function return more than one value?
Yes. Python returns them together, usually as a tuple.
Does code after return run?
No. Once return runs, the function stops.
See also
- Python functions explained
- Function parameters and arguments in Python
- How to create a simple function in Python
- Python print() function explained
- What is a return value in Python
Once you understand return values, try writing small functions that calculate something and send the result back. That is a big step toward writing reusable Python code.