# Sequential Search using Python

The Sequential search algorithm is a searching algorithm. To implement this algorithm, we start by searching for the target value from the beginning of the array and continue till we find the target value. In this article, I will take you through the implementation of Sequential Search using Python.

## Sequential Search Algorithm

The searching algorithms are the algorithms that are used to search a particular value in a data structure such as lists in Python. The sequential search is a searching algorithm that checks each item in a data structure from the beginning to find the target value.

For example, imagine that you are trying to find a specific card from a deck of cards. You will go through each card in the deck one by one until you find the card you are looking for. Once you got the card you were looking for you will stop. This is how the sequential search algorithm works. Now, in the section below, I will take you through an implementation of sequential search using the Python programming language.

## Sequential Search using Python

I hope you now know what a sequential search algorithm is and how it works. To implement this algorithm, we need to check each element from the beginning until we find the value we are looking for. Now letās see how to implement sequential search using Python:

In the Python code above, I have defined a Python function with two parameters(list_, n) the ālist_ā indicates the Python list and ānā indicates the item we want to search in a list. Then I am simply using a for loop to search for n in the list. Now letās see how to use the above function for implementing the sequential search algorithm:

```numbers = list(range(0, 20))
print(sequential_search(numbers, 3))```

Also, Read ā Python Projects with Source Code: Solved and Explained.

## Summary

The sequential search is one of those algorithms which are popular in every coding interview. To implement it, you have to search for the target value from the beginning of the data structure until you find the target value. I hope you liked this article on the implementation of Sequential Search using Python. Feel free to ask your valuable questions in the comments section below.

##### Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of dataš.

Articles:Ā 1370

1. #### Alugumetla Vijay

HI SIR. I HAVE IMPLEMENTED THIS CODE IN JUPYTER NOTEBOOK. I AM JUST GETTING āTRUEā as Output for whichever value i am giving. I didnāt understand this?. If I am giving n value greater than 20, even then I am getting True as Output.

• #### Aman Kharwal

Yes, it returns true if it finds the element in the specified range.

• #### Shogo takagi

Hi Sir, I have same idea as Alugumetra.
This argorithm might have a little problem. I implemented this code in jupyternotebook but it doesnāt work well.

def sequential_search(list_, n):
for i in list_:
if i == n:
break
return True

elements = range(0, 20)
ss = sequential_search(elements, 60)
print(ss)

I expected output is error or something else, but result was just True.
The value I wanted was 60, and my specified range is 0 to 19, so value is over range and couldnāt find but return True.
Could you tell us solution.

• #### Aman Kharwal

Thanks for notifying about the error, I have updated the code, it will work now

Tq u sir, for u r valuable time to spread knowledge.

• #### Aman Kharwal

Keep visiting šŗ