Find Largest element in an array using Python

 

Find Largest element in an array using python

Today we will learn how to find largest element in an array using Python Language. In this section first to find large element we have to declare an array size and store the first element value in the max variable and than loop through the array from i to the size of array and compare elements with values of the max and we find the desired result.
For Example:
Enter the array size 5
9
2
23
41
87
Largest element in an array 87

Python Program to find largest element in an array
Largest Element in an array in python

Steps needed for finding largest element in an array with help of Python

STEP 1: Initialize an array required in the code.

STEP 2: Store first element in variable max.

STEP 3: Iterate the loop through the array from i to length of the array and compare the value of max with elements of the array.

STEP 4: If we find any element is greater than max then max will hold the value of that element.

Python code:-

size=int(input("ENTER ARRAY SIZE "))
arr=[]
for i in range(size):
element=int(input())
arr.append(element)
print("LARGEST ELEMENTIS",max(arr))