Return value

The value a function hands back to its caller with the return statement.

A return statement ends a function and sends a value back to whoever called it, so you can store or use the result. A function with no return hands back None. Returning is different from printing: print() shows text on screen, while return gives a value back to your program.

Example
def total(prices):
    return sum(prices)      # hand the result back

bill = total([3, 5, 2])     # store the returned value
print(bill)
Output
10

Where this shows up in real Python

Return values let functions build on each other — one function’s result becomes another’s input, which is how larger programs are assembled.

Working with return values

  • return value — hand one value back
  • return a, b — return several values as a tuple
  • return — exit early, handing back None
  • result = f() — capture what a function returns

Related lessons