Edge cases with lists and strings
An unusual but allowed input, such as an empty list, a one-item list, repeated values, or the maximum at the start or end, that you test because it can break code.
Understanding Edge cases with lists and strings in ACARA Digital Technologies Years 9–10
What it does: With one item, index 0 and index -1 point to the same value, so loops that compare items may never run. An empty list is allowed input but unusual. Code like max_val = nums[0] crashes on it, so test it. The maximum 9 appears twice, so you must decide which position is correct (usually the first) and test it. An empty string has no first character, so name[0] causes an IndexError. An empty string is the string version of an empty list. Typical data often passes even when the code is faulty. Edge cases are where bugs hide. Repeated values test whether code that finds a maximum or sorts still works when no item is bigger than the others.
Common mistakes: For an empty list there is no item at index 0, so nums[0] raises an IndexError. The empty-list case should return a safe value such as 0. Indexes stop at len(items) - 1, so items[len(items)] is always out of range, even for a one-item list. Use items[-1] or items[len(items) - 1].
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 536–590) and word search (Modules 536–622).
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
edge caseFill in the Blanks
Spot the Error
Student with a class code? Join your class →