The dragon explains
def gives your code a name
The dragon: You've been writing print() lines one at a time. Functions let you name a whole GROUP of lines and reuse it.
The dragon: def roar(): starts a new ability called "roar". Everything indented under it belongs to that ability.
example.pyPython 3def roar(): print("ROAR!")
The dragon: But def alone doesn't DO anything — it just defines the ability. You have to actually CALL it.
example.pyPython 3def roar(): print("ROAR!")roar()
OutputROAR!The dragon: And you can call it as many times as you want, without ever rewriting the print() line inside it.
example.pyPython 3roar()roar()roar()
OutputROAR! ROAR! ROAR!
Quick check
Check your understanding
Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.
Question 1 of 2
def roar(): print("ROAR!") — with NO call anywhere after it. What happens when you run this?
question.pyPython 3def roar(): print("ROAR!")
- Nothing prints — defining an ability doesn't run itCorrect
- 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.
Question 2 of 2
roar() is called THREE separate times in your code. How many times does ROAR! print?
question.pyPython 3roar()roar()roar()
- Three times — once per callCorrect
- 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.
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
GuidedYour first try
def roar(): print("ROAR!") — defines an ability called roar. Call it TWICE by writing roar() twice, to make the dragon roar two separate times.
- +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 PROStuck three times? The game offers the answer — unasked.