Docstrings for functions and classes
A triple-quoted string on the first line of a function or class body. It documents what the code does, its parameters and its return value. help() displays it.
Understanding Docstrings for functions and classes in VCE Software Development U3O1
What it does: The docstring lists the parameter (price) with its type and meaning, and states what the function returns. The triple-quoted string is the first line indented inside the class, so it documents the Student class. Python only treats a string as the docstring if it is the first statement in the body. help() will not find it elsewhere. help() displays the docstring of a function or class. Functions do not have a .comment attribute. A docstring needs three double quotes (or three single quotes) at each end. Two quotes make an empty string followed by errors.
Common mistakes: The docstring is closed with only two quotes. A triple-quoted docstring must end with three double quotes: """. The function header is missing its colon. It should be def greet(name): so the docstring can sit in the function body.
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 48–71) and word search (Modules 10–71).
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
"""docstring"""Fill in the Blanks
Spot the Error
Student with a class code? Join your class →