CurriculumPython Functions, Parameters and return for Kidsdef gives your code a name

Python Functions and def Explained for Beginners

Write it once, call it as many times as you like — no retyping.

Lesson 1 of 5PROAges 10+
See what PRO unlocks →

def gives your code a name

You've been writing print() lines one at a time. Functions let you name a whole GROUP of lines and reuse it.

def roar(): starts a new ability called "roar". Everything indented under it belongs to that ability.

def roar():
    print("ROAR!")

But def alone doesn't DO anything — it just defines the ability. You have to actually CALL it.

def roar():
    print("ROAR!")

roar()

Output

ROAR!

And you can call it as many times as you want, without ever rewriting the print() line inside it.

roar()
roar()
roar()

Output

ROAR!
ROAR!
ROAR!

Check your understanding

def roar(): print("ROAR!") — with NO call anywhere after it. What happens when you run this?

def roar():
    print("ROAR!")
  • Nothing prints — defining an ability doesn't run it
  • ROAR! prints once, automatically

Why: Nothing prints. def roar(): ... just teaches Python the ability called "roar" — it has to be CALLED with roar() to actually run.

roar() is called THREE separate times in your code. How many times does ROAR! print?

roar()
roar()
roar()
  • Three times — once per call
  • Once — it's the same ability, so it only really happens once

Why: Three times. Every call runs the function's whole body again, from the top — calling it more than once means it happens more than once.

What you'll practice

def roar(): print("ROAR!") — defines an ability called roar. Call it TWICE by writing roar() twice, to make the dragon roar two separate times.

Unlock this lesson with PRO →

More from this topic

def gives your code a name is one lesson inside Python Functions, Parameters and return for Kids — see the full lesson order and what the whole topic covers.

View the full topic →