Home >>Python Programs >Python program to print the smallest element in an array
In this example, we will see a Python program through which we can find the smallest element in a given array and then print that element.
The smallest element can be found by looping through the array from start to end and comparing Min with all the other elements of the array. If any of element is smaller than the Min, then store a value of the element in Min. Initially, the Min will hold the value of the first element. At the end of the loop, Min will represent the smallest element in the array.
#Initialize array
arr = [25, 21, 7, 37, 56, 32, 84, 13, 9, 18];
#Initialize min with the first element of the array.
min = arr[0];
#Loop through the array
for i in range(0, len(arr)):
#Compare elements of array with min
if(arr[i] < min):
min = arr[i];
print("Smallest element present in given array: " + str(min));