Last modified: Feb 05, 2026 By Alexander Williams
Python Function Return Values Explained
Functions are the building blocks of Python programs. They package code for reuse.
A key part of a function is its output. This is handled by the return statement.
Understanding return is crucial for writing effective and modular code.
What is the Return Statement?
The return statement ends a function's execution. It sends a value back to where the function was called.
This value is called the "return value." It can be assigned to a variable or used directly.
Without a return statement, a function returns None by default.
Basic Return Syntax
The syntax is simple. Use the keyword return followed by the value or expression to send back.
Here is a basic example.
def add_numbers(a, b):
"""Adds two numbers and returns the result."""
result = a + b
return result # Sends the value of 'result' back
# Calling the function and storing its return value
sum_result = add_numbers(5, 3)
print(sum_result)
8
The function add_numbers calculates a sum. The return result line sends that sum back.
The value 8 is then assigned to the variable sum_result.
For a deeper look at how functions are built, see our Python Function Parts and Calls Explained guide.
Returning Multiple Values
Python functions can return multiple values. You separate them with commas.
Technically, Python returns them as a single tuple. You can unpack them into separate variables.
def get_user_info():
"""Returns multiple values as a tuple."""
name = "Alice"
age = 30
city = "London"
return name, age, city # This is a tuple: (name, age, city)
# Unpacking the returned tuple into three variables
user_name, user_age, user_city = get_user_info()
print(f"Name: {user_name}, Age: {user_age}, City: {user_city}")
Name: Alice, Age: 30, City: London
This is very powerful. It lets a function provide several related pieces of data at once.
It connects closely with concepts like Python Function Argument Unpacking.
The Implicit Return: None
If a function has no return statement, or if return is used alone, it returns None.
None is a special constant in Python. It represents the absence of a value.
def greet(name):
"""This function prints a greeting but returns None."""
print(f"Hello, {name}!")
# Calling the function
return_value = greet("Bob")
print(f"The function returned: {return_value}")
print(return_value is None) # Check if it's None
Hello, Bob!
The function returned: None
True
This is a common point of confusion for beginners. Printing is not the same as returning.
A function that prints cannot have its output assigned to a variable. Only a return value can.
Early Return for Control Flow
The return statement exits the function immediately. This is useful for early exits based on conditions.
Code after a return statement in the same block will never run.
def check_positive(number):
"""Returns a message based on the number's sign."""
if number > 0:
return "The number is positive." # Function exits here
elif number < 0:
return "The number is negative." # Function exits here
# If neither condition was True, the function continues here
return "The number is zero."
print(check_positive(10))
print(check_positive(-5))
print(check_positive(0))
The number is positive.
The number is negative.
The number is zero.
This pattern makes code cleaner. It avoids deep nesting with else statements.
Returning Different Data Types
A function can return any Python data type. This includes lists, dictionaries, and even other functions.
The return type is not declared. It is determined at runtime.
def create_report(scores):
"""Analyzes a list of scores and returns a summary dict."""
if not scores: # Check if list is empty
return {} # Return an empty dictionary
report = {
"average": sum(scores) / len(scores),
"highest": max(scores),
"lowest": min(scores)
}
return report
exam_scores = [85, 92, 78, 90, 88]
summary = create_report(exam_scores)
print(summary)
{'average': 86.6, 'highest': 92, 'lowest': 78}
This flexibility is a strength of Python. A single function can handle different cases and return appropriate types.
To understand how to define the function itself, review our Python Function Syntax Guide for Beginners.
Common Mistakes and Best Practices
Here are key points to remember about using return effectively.
Mistake 1: Confusing print with return. Use print() for displaying information to the user. Use return to send data to other parts of your code.
Mistake 2: Code after a return statement. Any code in the same block after a return is unreachable and will be ignored.
Best Practice: Have a single return point. While early returns are useful, for complex functions, having one main return at the end can improve readability.
Best Practice: Return meaningful values. Design your functions to return the data the caller needs. Avoid functions that only perform side effects like printing.
Conclusion
The return statement is fundamental in Python. It controls what data a function produces.
You can return single values, multiple values, or None. You can use it for early exits and to send back complex data structures.
Mastering return separates code that merely runs from code that is reusable, testable, and modular.
Remember, a function's return value is its primary way of communicating with the rest of your program. Use it wisely.