The return statement sends a value back to whatever called the function and immediately ends the function's execution — any code after return in the same block never runs. A function without an explicit return, or one that reaches the end of its body without hitting one, returns None automatically.
#how it works
1
return value ends the function immediately
Sending value back to the caller right away.
2
Code after return is unreachable
Anything written after it in the same code path never runs.
3
No value means None
return with nothing after it, or no return at all, makes the function return None.
4
return can exit early
It can appear inside a loop or conditional to stop the function before reaching its end.
5
Multiple values pack into a tuple
return a, b sends both back at once, automatically packed together.
#example
def classify(n):
if n < 0:
return "negative"
return "non-negative"
print(classify(-5))
print(classify(5))
def min_max(numbers):
return min(numbers), max(numbers)
low, high = min_max([4, 1, 7, 3])
print(low, high)
Output
negative
non-negative
1 7
1classify(-5) hits the if branch, returning "negative" immediately — the second return line is never reached for this call.
2classify(5) skips the if branch entirely (since 5 < 0 is False), falling through to the second return, "non-negative".
3min_max([4, 1, 7, 3]) returns two values at once, which Python packs into a tuple; low, high = ... unpacks them straight back into two variables.
#use cases
Sending a computed result back to wherever a function was called from
Exiting a function early once an answer is found, like returning as soon as a match is located in a loop
Returning several related values from one function call, like a minimum and maximum together
Distinguishing a function that produces a value (with return) from one that just performs an action (like print)
Practice Python interview questions
Every Python lesson maps to the matching interview topic, with answers written for current Python versions.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses →Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free →Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books →