Python Program to Find the Largest Number in a Given List
Hey There,
In this video, I have shown how to find the largest number in a given list.
Consider the given list as : list = [2,4,6,8,1,9,3,0]
Now,sort the list to get the largest number at the last. The sorting can be done as : list.sort()
After sorting the list look like : list = [0,1,2,3,4,6,8,9]
We got the largest number in the list at the end.
To print the last element in the list, we can write the code as : print(list[-1])
So,the code can be written as :
list = [2,4,6,8,1,9,3,0]
list.sort()
b = list[-1]
print("Largest number in the given list is : ",b)
Output :
Comments
Post a Comment