Functions – Defining
def defines a named, reusable block of code that runs when called
What it does: A function is a reusable, named block of code, created with the def keyword: def greet():. The indented lines underneath — the function body — only run when the function is called by writing its name followed by parentheses: greet(). Defining a function doesn't run it; nothing happens until it's actually called, which is what lets the same code run many times from different places in a program.
Common mistakes: Forgetting the colon at the end of the def line (def greet() instead of def greet():) is the most common error. Another is defining a function but forgetting to call it — the code inside never runs on its own.
Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.
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
defFill in the Blanks
Spot the Error
Create a free class, add this module to a journey, and track who's stuck.
Create a free teacher account →No credit card. No setup fee. Make a class and invite students in under three minutes.
Practice this topic interactively, track progress, and unlock badges.
Start Learning Free →