Python Program to find the largest and smallest element of an array


In this program, you will learn how to find the largest and smallest element of an array in Python.


a = arr.array('i', [40, 30, 10, 90, 55])

Example: How to find the largest and smallest element of an array in Python

import array as arr

a = arr.array('i', [40, 30, 10, 90, 55])

largest = smallest = a[0]

for i in a:
    if largest < i:
        largest = i

    if smallest > i:
        smallest = i

print("Largest element is : ", largest)
print("Smallest element is : ", smallest)

Output:

Largest element is :  90
Smallest element is :  10