Ad – 728Γ—90
βš™οΈ 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))   # 
β–Ά Output
Hello, Alice! None
Ad – 336Γ—280

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