Functions that change a list or return a new one
A function can change a list you pass in, altering the original in place. Make a copy with [:] first if you need to keep the original list unchanged.
Understanding Functions that change a list or return a new one in ACARA Digital Technologies Years 9–10
What it does: The function changes only new_scores, a copy, and returns it, so the original scores list stays the same. items and nums refer to the same list, so after the call nums becomes [2, 3]. append() changes the list object itself, so the caller's list is altered even though nothing is returned. Slicing with [:] copies the whole list, giving a new list you can change safely. Assignment only gives the list a second name, whereas items[:] builds a new list. Functions without a return statement give back None, so nums does not hold the list.
Common mistakes: A function definition must end with a colon. It should be def add_bonus(scores):. Lists have no add() method. Use append() to add an item to the end of the list, so the original list is changed in place.
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
copy = items[:]Fill in the Blanks
Spot the Error
Student with a class code? Join your class →