Skip to main content
Albero Academy

Return Values

Return single or multiple values, and understand None.

Functions8 min

return hands a value back to whoever called the function, and immediately ends the function. Understanding return — including how to give back several values and what happens when you omit it — is essential to composing functions together.

Returning a value

return ends the function
def double(n):
return n * 2
print("never runs") # unreachable — return already exited
result = double(21) # 42 — the returned value

Returning multiple values

Return several values as a tuple (the commas make it one), then unpack them at the call site:

multiple returns via a tuple
def stats(xs):
return min(xs), max(xs), sum(xs) / len(xs)
lo, hi, avg = stats([4, 8, 6]) # lo=4, hi=8, avg=6.0

Returning None

A function with no return (or a bare return) gives back None. Use a bare return for an early exit:

early exit and None
def log(msg):
print(msg) # no return → returns None
def withdraw(balance, amount):
if amount > balance:
return # early exit, returns None
return balance - amount

Key takeaways

  1. 01return sends a value back and immediately ends the function.
  2. 02Return a tuple (comma-separated) to give back multiple values; unpack at the call site.
  3. 03A function without return (or a bare return) yields None.
  4. 04A bare return is a clean early exit.
  5. 05Prefer returning values over printing inside functions — it keeps them testable.

Finished this chapter?

Mark it complete to track your progress through Python.