Junior Codes
Willow Island

Python Functions for Kids

Invent your own command with def and use it as often as you like.

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.

Functions, explained simply

You have already used a function: print(). Someone else wrote it so you could use it with one word. With def, you can invent functions of your own.

Defining a function is like writing a recipe card. You give it a name, write the steps underneath (indented), and put the card away. Nothing happens yet.

The steps run when you call the function by writing its name followed by brackets. Call it once, or a hundred times, and you never have to rewrite the steps.

Example: A delivery helper

def deliver():
    print("Pick up the parcel")
    print("Carry it to the door")

deliver()
deliver()

Output

Pick up the parcel
Carry it to the door
Pick up the parcel
Carry it to the door

Try this

  • Write a function called cheer() that prints a short celebration, then call it three times.
  • Define a function but forget to call it. What happens when you run the program?
  • Call one function from inside another function.

Practise it in Wonderwild

“The delivery invention”

Mission 5 in Willow Island, 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

Why use a function instead of copying the code?+

If you need to change the steps, you change them in one place and every call gets the update. Functions also give a block of code a helpful name, which makes programs easier to read.

Why are there brackets after a function name?+

The brackets are how you tell Python to run the function now. Later you will put information inside them, called arguments.

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