Storing objects in a list
Adds an object to the end of a list so many objects are stored together. You can then loop over the list with a for loop to call each object's methods or find one by its attribute.
Understanding Storing objects in a list in VCE Software Development U4O1
What it does: Empty square brackets make a list with nothing in it yet, ready for append() to add objects. Inside a loop, comparing an attribute such as p.name to a value lets you pick out the matching object. Python lists use the append() method to add an item to the end. There is no add() method on a list. The loop variable (pet) holds one object at a time, so you call the method on pet. A list has no show() method. Use == to compare values. A single = is assignment and causes a syntax error in an if statement. [] creates an empty list. Student() would create one Student object (and needs the right arguments), not a list.
Common mistakes: A tuple () cannot be added to, so append() would fail. Create an empty list with pets = []. A for loop header must end with a colon. It should be for d in dogs:.
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 3–79) and word search (Modules 3–114).
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
objects.append(obj)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →