Python Program to find Largest Number in a List

In this article, we will show you, How to write a Python Program to find Largest Number in a List with practical example. Before you start, please refer List article to understand everything about Lists.

Python Program to find Largest Number in a List Example 1

The max function in python will return the maximum value in a List

# Python Program to find Largest Number in a List
a = [10, 50, 60, 80, 20, 15]
print("The Largest Element in this List is : ", max(a))

OUTPUT

Python Program to find Largest Number in a List Example 2

This python program is same as above but this time we are allowing user to enter the length of a List. Next, we used For Loop to add numbers to the list.

# Python Program to find Largest Number in a List
NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
print("The Largest Element in this List is : ", max(NumList))

OUTPUT

Python Program to find Largest Number in a List Example 3

The Sort function in python will sort List elements in ascending order. Next, we are using the Index position to print Last element in a List

# Python Program to find Largest Number in a List
a = [10, 50, 60, 80, 20, 15]
a.sort()
print("The Largest Element in this List is : ", a[5])

OUTPUT

Python Program to find Largest Number in a List Example 4

This is same as above but this time we are allowing user to enter his own list items.

# Python Program to find Largest Number in a List
NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
NumList.sort()
print("The Largest Element in this List is : ", NumList[Number - 1])

OUTPUT

Python Program to find Largest Number in a List Example 5

This program will sort list items in Ascending order. Next, we used reverse function to reverse the list items. Lastly, we used index position 0 to print first element in a list

# Python Program to find Largest Number in a List
NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
NumList.sort()
NumList.reverse()
print("The Largest Element in this List is : ", NumList[0])

OUTPUT

Python Program to find Largest Number in a List Example 6

In this program we are not using any built-in function such as sort, reverse, or max function

# Python Program to find Largest Number in a List
NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
largest = NumList[0]
for j in range(1, Number):
if(largest < NumList[j]):
largest = NumList[j]
position = j
print("The Largest Element in this List is : ", largest)
print("The Index position of the Largest Element is : ", position)

First Iteration – for 1 in range(1, 5) – Condition is true So, it will start executing If statement inside the loop until the condition fails. If (largest < NumList[j]) inside the for loop is True because (70 < 80) largest = NumList[1] largest = 80 position = 1