PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Linear Search in Python

← All stacks

Theory

75/268

Linear Search in Python

Linear search checks each item from start to end until it finds the target. Works on unsorted lists. Worst case you look at all n items — O(n). Code is a for-loop and an if. Acceptable on small lists or when data is not sorted. On a huge sorted list, binary search is the better story.

Trace [4, 1, 3, 2] looking for 3: check 4, check 1, check 3 — found. Say O(n) honestly. Don’t claim it is “always slow” — for n=10 it is fine.

Linear Search in Python — output — 1. 90 is at index 1. If missing, found stays -1.

Exam tip

When linear search is acceptable.

Example

# Linear search
marks = [70, 90, 80]
key = 90
found = -1
for i, x in enumerate(marks):
    if x == key:
        found = i
        break
print(found)

Linear Search in Python — output: 1. 90 is at index 1. If missing, found stays -1.

Short notes

  • DefScan one by one.
  • RuleWorks unsorted. O(n).
  • RememberEasy to code.

Questions

1

Explain Linear Search as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Linear Search?

Previous← Searching Algorithms in PythonNextBinary Search in Python →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.