Linear search in Python
An algorithm that uses a loop to check each item in a list in turn. It stops when it finds the target or reaches the end of the list, often returning the index or -1.
Understanding Linear search in Python in VCE Software Development U3O1
What it does: Returning i inside the loop ends the function straight away and reports the index where the target was found. range() needs a number, so use len(scores) to get how many items there are. range(scores) would cause a TypeError. Jumping to the middle and halving is binary search. Linear search checks items one at a time from the start. -1 is not a valid index, so it clearly means 'not found'. 0 is the first index, so it would look like a match at the start of the list. == compares two values. A single = assigns a value and causes a SyntaxError inside an if statement.
Common mistakes: A single = assigns a value, so it causes a syntax error inside an if. Use == to compare: if nums[i] == target:. With != the function returns the index of the first item that is NOT the goal. Linear search must check for a match using ==.
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 142–155) and word search (Modules 142–166) and definitions worksheet (Modules 142–155) and word scramble (Modules 142–155).
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
▶ Run these on the board — two answers, the class points left or right, you reveal why. No devices.
Match the Pairs
Key Term
linear searchFill in the Blanks
Spot the Error
Student with a class code? Join your class →
Classroom tools: Hangman · Bingo · Heads or Tails · Higher or Lower · Name Picker · Team Generator · Seating Plan