
Python’s return
keyword commands the execution flow to exit a function immediately and return a value to the caller of the function. You can specify an optional return value—or even a return expression—after the return
keyword. If you don’t provide a return value, Python will return the default value None
to the caller.
Python Return Keyword Video
Return Keyword Followed by Return Value
Here’s an example of the return keyword in combination with a return value:
def f(): return 4 print(f()) # OUTPUT: 4
Within function f()
, Python returns the result 4 to the caller. The print()
function then prints the output to the shell.
Return Keyword Followed by Return Expression
Here’s an example of the return keyword in combination with a return expression:
def f(): return 2+2 print(f()) # OUTPUT: 4
Within function f()
, Python evaluates the expression 2+2=4
and returns the result 4 to the caller. The print()
function then prints the output to the shell.
Return Keyword Followed by No Value
Here’s an example of the return keyword without defining a return value:
def f(): return print(f()) # OUTPUT: None
Within function f()
, Python returns the default value None
to the caller. The print()
function then prints the output to the shell.
Interactive Code Shell
Run the following code in your browser:
Exercise: Change the three return values to 42, 42, and ‘Alice’ in the interactive code shell!
🌍 Recommended Tutorial: What’s the Difference Between return and break in Python?

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.