Junior Codes
Inventor Studio

Python return for Kids: Getting Answers from Functions

Send an answer back from a function so the rest of the code can use it.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

return, explained simply

Some functions do a job, like printing a message. Others work something out and hand the answer back. That is what return is for.

When Python reaches return, it leaves the function straight away and gives back the value after it. You can store that value in a variable, print it, or use it in more maths.

print() only shows something on the screen. return gives the value back to your program. A function that prints an answer cannot be used in a calculation; one that returns it can.

Example: Work out a cost

def bridge_cost(planks):
    return planks * 15

small = bridge_cost(4)
big = bridge_cost(10)
print(small + big)

Output

210

Try this

  • Change return to print inside the function and see what small + big does now.
  • Write a function that returns the bigger of two numbers.
  • Add a line after return inside the function. Does it ever run?

Practise it in Wonderwild

“The bridge-cost calculator”

Mission 26 in Inventor Studio, one of 36 Python missions in Wonderwild.

Your child writes and runs real Python in the browser while Pip reacts to every line. Nothing to install. For ages 7+.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Questions parents and kids ask

What does a function return if there is no return line?+

It returns a special value called None, which means "nothing". That is why printing the result of such a function shows None.

Can a function return more than one value?+

Yes, write return a, b and Python sends back a tuple, which you can unpack with x, y = my_function().

Prefer learning with a teacher?

Our live Python for Young Developers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the Python for Young Developers course