











Find the Smallest and largest element in an array using Python


Smallest and Largest Element
Today in this section we will learn how to find the smallest and largest element in an array using Python Language.To find elements we have to enter the length of a List than we apply For Loop to add numbers in the list.
We use the min and max functions in Python which returns the smallest and largest element from the List or array.
For Example:
Input : [12,3,54,7,87,34,99]
Output : Smallest Element is 3
Largest Element is 99
Implementation for finding largest and smallest number in the list
Step 1: Enter the user defined input of the list using input().
Step 2: Initialize an empty list arr = [] .
Step 3: Iterate through a each element using a For loop .
Step 4: In the For loop append every element to the list.
Step 5: In Python we use predefined function max() to find the largest element in a list.
Step 6: Likewise, we use predefined function min() to find the smallest element in a list.
Code in Python to find Smallest and Largest element in an array
size=int(input("ENTER ARRAY SIZE"))
arr=[]
for i in range(size):
element=int(input())
arr.append(element)
print("SMALLEST ELEMENT",min(arr))
print("LARGEST ELEMENT",max(arr))
Login/Signup to comment