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.
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!")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()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.
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 →