Python Function Parameters: Customising What a Function Does

Fireball, but bigger — the same function, a different result each time you call it.

  • Lesson 2 of 5
  • PRO
  • Ages 10+
  • 3 hands-on levels
See what PRO unlocksA one-time $49.99 purchase. Topics 1–3 are free.

The dragon explains

Parameters customise the ability

  1. The dragon: def roar(): always does the exact same thing. Parameters let a call CHANGE what happens.

  2. The dragon: def greet(name): — name is a PARAMETER, a blank the caller fills in when they call it.

    example.pyPython 3
    def greet(name):    print("Hello,", name)greet("Ember")
    OutputHello, Ember
  3. The dragon: Call it again with a different value, and you get a different result — same function, no rewriting.

    example.pyPython 3
    greet("Blaze")
    OutputHello, Blaze
  4. The dragon: This is the whole idea of 'fireball, but bigger' — one ability, customised each time you cast it.

Quick check

Check your understanding

Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.

  1. Question 1 of 1

    def fireball(size): print("SIZE:", size). What does fireball(20) print, compared to fireball(5)?

    question.pyPython 3
    def fireball(size):    print("SIZE:", size)
    • SIZE: 20 — using the value passed in THIS callCorrect
    • SIZE: 5 — the first value it was ever called with

    Why: SIZE: 20. Each call passes its own value for the parameter — fireball(20) uses 20, completely independent of any earlier call.

In the game

What you'll practice

Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.

  1. 1

    GuidedYour first try

    def greet(name): print("Hello,", name) — the ability now TAKES a name and uses it. Call greet("Ember") and greet("Blaze") — two different dragons, two different greetings.

  2. +2

    PracticeTwo more, on your own

This lesson is part of PRO.

PRO is a one-time $49.99 purchase, no subscription, and unlocks this whole topic along with everything else. Topics 1–3 are free, start to finish.

Unlock this lesson with PRO

Stuck three times? The game offers the answer — unasked.