Python Linear Search
Linear search means checking each element in an array in order until the specific value being searched for is found.

Example
def
search
(
arr
,
n
,
x
)
:
for
i
in
range
(
0
,
n
)
:
if
(
arr
[
i
]
==
x
)
:
return
i
return
1
Search for character D in array arr
arr
=
[
'
A
'
,
'
B
'
,
'
C
'
,
'
D
'
,
'
E
'
]
x
=
'
D
'
n
=
len
(
arr
)
result
=
search
(
arr
,
n
,
x
)
if
(
result
== -
1
)
:
(
"
The element is not in the array
"
)
else
:
(
"
The index of the element in the array is
"
,
result
)
The output of the code above is:
元素在数组中的索引为 3
Python3 Examples