Write a Python program to find the largest element in an array :
a=[56,78,34,90,23,56,34]
a.sort()
print("The largest element is",a[-1])
Output:
The maximum element is 90
The given code sorts the list a
in ascending order and then prints the largest element in the list.
After sorting the list, the largest element will be the last element in the sorted list, which can be accessed using the index -1
. So the code is correct as it is.
If you are a beginner and want to know more about Python programming, you can read my Basics of Python blogs (From part 1 to part 15).
HAPPY LEARNING !!!