Write a Python program to get the largest number from a list


The program is a Python script that demonstrates two ways of finding the largest number in a list of numbers. The first method is to use the built-in Python function "max()" and passing the list as an argument. The second method is to use a for loop to iterate through the list, comparing each number to a variable named "max" which is initialized as the first element of the list. If any number in the list is greater than "max", the loop updates "max" to that number. Finally, the program prints the largest number found in the list.

Source Code

a=[1,7,10,34,2,8]
"""
print("Largest Number :",max(a))
"""
max = a[ 0 ]
for i in a:
	if i > max:
		max = i
print("Largest Number :",max)
 

Output

Largest Number :34

Example Programs