Skip to content
dreamcode
dreamcode
Map
Return values
Lesson 22 of 77
+15 XP on finish
PYTHON BASICSChapter 4 · Functions

Sending data back

A function can calculate a result and send it back to the caller using the return keyword. Once a function returns, it exits immediately. If you do not write return, the function returns None.

Worked example

How it reads

  • **return x * 2** calculates the value and immediately finishes the function
  • result = double(10) captures the returned value (20) and stores it in result
Cloud tip: Do not confuse print() and return. print() displays text to the screen, while return passes data back to your code so you can use it in other calculations.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Write is_even(n) that returns True or False, then print is_even(10) and is_even(7).

Press Run to check your work.