Basic Return Statement
return immediately exits the function and sends the specified value back to whoever called the function.
def add(a, b):
return a + b
result = add(3, 7)
print(result) # 10
print(add(100, 200)) # 300 - use directly
Functions Without return → None
If a function has no return statement (or just return with no value), it returns None.
def greet(name):
print(f"Hello, {name}!") # No return statement
result = greet("Alice")
print(result) # None
print(type(result)) # <class 'NoneType'>
Returning Multiple Values
Python functions can return multiple values by separating them with commas. Python packs them into a tuple automatically.
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)
Early Return – Guard Clauses
Returning early when a condition fails is cleaner than deep nesting.
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
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.
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}")
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
| Return | Behavior |
|---|---|
| a value | caller receives it |
| multiple (comma) | packed into a tuple |
| nothing / no return | returns 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:
- Write
square(n)that returnsn * nand use its result in an expression. - Write a function with no
returnand confirm it returnsNone. - Write
divmod_custom(a, b)that returns both quotient and remainder. - Use an early
returnas 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
returnsends a value back to the caller and ends the function immediately.- A function with no
return(or a barereturn) returnsNone. - Returning multiple values actually returns a tuple, which the caller can unpack.
returnhands data back for further use;printonly displays text and returnsNone.- Early returns (guard clauses) handle edge cases up front and keep the main logic flat.
- Any code after a reached
returnis never executed.
Interview Questions on Return Values
- What does the
returnstatement do? - What does a function return if it has no
returnstatement? - How does a function return multiple values?
- What is the difference between
returnandprint? - 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
returnstatement?
Related Topics
FAQ
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.
It returns them separated by commas, which Python packs into a tuple: return a, b. The caller can unpack it with x, y = func().
return? +It returns None. The same happens with a bare return that has no value, which is often used to exit early.
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.

