Lesson 22 of 34

return: Giving Back an Answer

8 min 30 XP

print() only shows something on screen. return hands a value back to the caller, so you can store it or use it in calculations.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

A function stops as soon as it reaches return. A function without return gives back None.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

From now on, hidden tests will call your function with other values. So your return value must be right!

Challenge

+30 XP

Write a function is_even(n) that returns True if n is even, otherwise False (return, not print!).

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.