Home >>Python Programs >Python program to print the largest element in an array
In this example, we will see a Python program through which we can find the largest element in a given array and then print that element.
The largest element can be found by looping through the array from start to end and comparing max with all the other elements of the array. If any of element is greater than the max, then store a value of the element in max. Initially, the max will hold the value of the first element. At the end of the loop, max will represent the largest element in the array.
#Initialize array
arr = [10,25,12,17,79,53];
#Initialize max variable with first element of array.
max = arr[0];
#Loop through the array
for i in range(0, len(arr)):
#Compare elements of array w ith max variable and find greater than max then ovveride max variable with new value
if(arr[i] > max):
max = arr[i];
print("Largest element in given array = " + str(max));