Advertisement
⚙️ Functions

Python Return Values – Return Statement and Multiple Returns

The return statement sends a value back from a function to the caller. Without it, a function returns None. Understanding how to effectively use return values — including returning multiple values, early returns, and conditional returns — makes your functions much more powerful.

⏱️ 18 min read 🎯 Beginner 📅 Updated 2026

Basic Return Statement

return immediately exits the function and sends the specified value back to whoever called the function.

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

result = add(3, 7)
print(result)       # 10
print(add(100, 200))  # 300 - use directly
▶ Output
10 300

Functions Without return → None

If a function has no return statement (or just return with no value), it returns None.

Python
def greet(name):
    print(f"Hello, {name}!")  # No return statement

result = greet("Alice")
print(result)   # None
print(type(result))   # <class 'NoneType'>
▶ Output
Hello, Alice! None <class 'NoneType'>
Advertisement

Returning Multiple Values

Python functions can return multiple values by separating them with commas. Python packs them into a tuple automatically.

Python
def min_max(numbers):
    return min(numbers), max(numbers)  # Returns tuple

low, high = min_max([5, 3, 9, 1, 7])  # Unpack
print(f"Min: {low}, Max: {high}")

# Or capture as a single tuple
result = min_max([5, 3, 9, 1, 7])
print(result)   # (1, 9)
▶ Output
Min: 1, Max: 9 (1, 9)

Early Return – Guard Clauses

Returning early when a condition fails is cleaner than deep nesting.

Python
def divide(a, b):
    if b == 0:
        return None  # Early return for invalid input
    return a / b

print(divide(10, 2))   # 5.0
print(divide(10, 0))   # None - early return triggered
▶ Output
5.0 None

Returning Different Types

A function can return different types based on conditions. This is valid Python but can make code harder to use — callers must check the type.

Python
def find_user(user_id):
    users = {1: "Alice", 2: "Bob"}
    if user_id in users:
        return users[user_id]  # Returns str
    return None               # Returns NoneType

user = find_user(1)
if user is not None:
    print(f"Found: {user}")
▶ Output
Found: Alice

Return Values: One, Many, or None

return does two things at once: it sends a value back and immediately exits the function. Everything after a return that runs is dead code.

def divide(a, b):
    if b == 0:
        return None          # early exit — guard against divide-by-zero
    return a / b             # normal result

# return MULTIPLE values (actually returns a tuple)
def min_max(nums):
    return min(nums), max(nums)

low, high = min_max([3, 1, 8])   # unpack the tuple → low=1, high=8
ReturnBehavior
a valuecaller receives it
multiple (comma)packed into a tuple
nothing / no returnreturns None

Multiple returns are really a tuple: return a, b builds a tuple, and x, y = func() unpacks it — a clean way to hand back several results without a container class. Early return (returning inside a guard at the top) is a readable alternative to nesting the whole function in an if. Consistency matters: if a function sometimes returns a number and sometimes None, callers must check for None — document that. Avoid returning different types from different branches when you can; predictable return types make functions easier to use correctly.

🏋️ Practical Exercise

Practice returning data:

  1. Write square(n) that returns n * n and use its result in an expression.
  2. Write a function with no return and confirm it returns None.
  3. Write divmod_custom(a, b) that returns both quotient and remainder.
  4. Use an early return as a guard clause to handle an invalid input.

🔥 Challenge Exercise

Write a function analyze(numbers) that returns a tuple of the count, sum, average, minimum, and maximum of a list. Use an early return to handle the empty-list case gracefully (return None or a sentinel). Unpack the returned tuple at the call site and print a formatted report. Bonus: return a dictionary instead and compare readability.

📋 Summary

  • return sends a value back to the caller and ends the function immediately.
  • A function with no return (or a bare return) returns None.
  • Returning multiple values actually returns a tuple, which the caller can unpack.
  • return hands data back for further use; print only displays text and returns None.
  • Early returns (guard clauses) handle edge cases up front and keep the main logic flat.
  • Any code after a reached return is never executed.

Interview Questions on Return Values

  • What does the return statement do?
  • What does a function return if it has no return statement?
  • How does a function return multiple values?
  • What is the difference between return and print?
  • What is an early return / guard clause?
  • Can a function return different types depending on input? Is that a good idea?
  • What happens to code after a return statement?

FAQ

What is the difference between return and print? +

print only shows text in the console and the function still returns None. return hands an actual value back to the caller so it can be stored, passed on, or used in further calculations.

How does a function return more than one value? +

It returns them separated by commas, which Python packs into a tuple: return a, b. The caller can unpack it with x, y = func().

What does a function return if there is no return? +

It returns None. The same happens with a bare return that has no value, which is often used to exit early.

Why does code after return not run? +

return ends the function call immediately and transfers control back to the caller, so any statements below it in the same path are unreachable.