Defining a function with def
Creates a function: a named, reusable block of indented code that only runs when you call it. Define it first, then call it.
Understanding Defining a function with def in Years 7–8 Creating Digital Solutions
What it does: The def block creates the function, and the call cheer() on the last line runs it. The definition comes before the call. The name say_hello is followed by () and a colon. The print line is indented so it is part of the function body. Python uses the keyword def to define a function. It does not use function. Function names cannot have spaces. Use an underscore like show_score instead.
Common mistakes: Text inside print() must be in quote marks. It should be ' print("Hi!")'. A def line must end with a colon. It should be 'def welcome():'.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 50–125) and word search (Modules 3–125).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
def name():Fill in the Blanks
Spot the Error
Student with a class code? Join your class →