
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program for Linear Search
In this article, we will learn about the Linear Search and its implementation in Python 3.x. Or earlier.
Algorithm
Start from the leftmost element of given arr[] and one by one compare element x with each element of arr[] If x matches with any of the element, return the index value. If x doesn’t match with any of elements in arr[] , return -1 or element not found.
Now let’s see the visual representation of the given approach −
Example
def linearsearch(arr, x): for i in range(len(arr)): if arr[i] == x: return i return -1 arr = ['t','u','t','o','r','i','a','l'] x = 'a' print("element found at index "+str(linearsearch(arr,x)))
Output
element found at index 6
The scope of the variables are shown in the figure −
Conclusion
In this article, we learned about the mechanism of linear search in Python3.x. Or earlier.
- Related Articles
- Write a program for Linear Search in Python
- Linear Search in Python Program
- C/C++ Program for Linear Search?
- Python Program for Binary Search
- Java program to implement linear search
- 8085 Program to perform linear search
- Python Program for Anagram Substring Search
- Linear Search
- Program to perform linear search in 8085 Microprocessor
- Linear search on list or tuples in Python
- Difference Between Linear Search and Binary Search
- Linear search in Java.
- Python Program for Depth First Binary Tree Search using Recursion
- Implementing Linear Search in JavaScript
- 8085 program for Binary search

Advertisements