Junior Codes
Inventor Studio

Python Function Parameters and Default Values for Kids

Pass information into a function, with sensible defaults.

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.

Parameters & defaults, explained simply

A function that always does exactly the same thing is useful, but a function you can customise is much more powerful. Parameters are the names inside the brackets of def. They act like variables that get filled in each time the function is called.

The values you pass when you call the function are called arguments. stamp("star") passes "star" into the shape parameter.

You can give a parameter a default value with an equals sign in the def line. If the caller leaves it out, the default is used; if they supply one, theirs wins.

Example: A stamp maker

def stamp(shape, copies=1):
    for i in range(copies):
        print("Stamped a", shape)

stamp("star")
stamp("moon", 2)

Output

Stamped a star
Stamped a moon
Stamped a moon

Try this

  • Add a colour parameter with a default of "blue" and include it in the message.
  • Call the function with copies=3 written by name.
  • Call stamp() with no arguments at all and read the error.

Practise it in Wonderwild

“The custom stamp workshop” and “Choose your welcome”

Mission 25 and Mission 28 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 is the difference between a parameter and an argument?+

The parameter is the name in the def line. The argument is the actual value you pass in when you call the function.

Where do parameters with defaults go?+

After the ones without defaults. def stamp(shape, copies=1) is fine; def stamp(copies=1, shape) is a syntax error.

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