Building and returning a list from a function
Start a function with an empty list, append each wanted item inside a loop, then return the finished list after the loop ends. Filtering builds a new list.
Understanding Building and returning a list from a function in ACARA Digital Technologies Years 9–10
What it does: Only marks that pass the if test are appended, so the new list holds a filtered selection. The return is outside the loop, so it runs once after every item has been added. An empty list [] gives you somewhere to collect items. A number like 0 cannot use append(). append() adds the item to the end of the list. Using = replaces the whole list with a single value. The function only reads the original list and appends wanted items to result, so the original is untouched. The accumulator list starts empty so each wanted item can be appended to it later.
Common mistakes: An if statement must end with a colon. The line should be: if m >= 50:. {} makes an empty dictionary, not a list, so append() would fail. Start with an empty list: evens = [].
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 629–680) and word search (Modules 629–707).
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
result = []Fill in the Blanks
Spot the Error
Student with a class code? Join your class →