# Find Smallest element in an array using Python

## Find smallest element in an array using Python

In this section we will learn how to find smallest element in an array using python programming language which is the scripting language. If we want to find smallest element from the array enter by the user so we have to compare one element to other until we get the desired element and print it. To find the minimum element in the given list or array we can use different approaches to get the minimum element. Here, in this page we will discuss the following algorithms to find the minimum/smallest element.

• Method 1 : Using Iteration
• Method 2 : Using sorting
• Method 3 : Using min() function

## Method 1 :

• Take a variable say mini to store the minimum element of the array.
• Set mini = arr
• Run a loop over the array
• Check if(arr[i]<mini) then set mini = arr[i]
• After complete iteration print mini.

### Method 1 : Python code

Run
```arr = [10, 89, 9, 56, 4, 80, 8]
mini = arr

for i in range(len(arr)):
if arr[i] < mini:
mini = arr[i]

print (mini)```

`4`

## Method 2 :

• Sort the array using sort() function.
• Print the first element of the array. ### Method 2 : Python Code :

Run
```arr = [10, 89, 9, 56, 4, 80, 8]
arr.sort()

print (arr)
```

`4`

## Method 3:

Using min() inbuilt function.

• Declare an array.
• Print the min(arr)

### Method 3 : Python code

Run
```arr = [10, 89, 9, 56, 4, 80, 8]
print (min(arr))```

### Output :

`4` ### 2 comments on “Find Smallest element in an array using Python”

• here, arr=[] means list not an array. In python we need to import array module to use array. 6
• Arun

from array import *
a=array(“i”,[])
b=int(input(“enter size :”))
for x in range(b):
c=int(input())
a.append(c)
print(min(a)) 0