# Python Program to find Largest Number in a List

Write a Python Program to find the Largest Number in a List with a practical example.

## Python Program to find the Largest Number in a List Example 1

The Python max function returns the maximum value in a List.

```# Python Program to find Largest Number in a List

a = [10, 50, 60, 120, 20, 15]

print("The Largest Element in this List is : ", max(a))```

Python largest list number output

``The Largest Element in this List is : 120``

## Python Program to find Largest Number in a List Example 2

This python program for the maximum list number is the same as above. But this time, we are allowing the user to enter the length of a List. Next, we used For Loop to add numbers to the Python 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))```

## Python Program to find Largest Number in a List Example 3

The Python sort function sort the List elements in ascending order. Next, we use the Index position to print the Last element in a List.

```a = [10, 50, 60, 80, 20, 15]

a.sort()
print("The Largest Element in this List is : ", a)```

Python maximum list number output

``````The Largest Element in this List is :  80
>>> ``````

## Python Program to find Largest Number in a List Example 4

This Python largest list number program is the same as above. But this time, we allow the user to enter their own list items.

```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])```

Python largest list number output

``````Please enter the Total Number of List Elements: 3
Please enter the Value of 1 Element : 90
Please enter the Value of 2 Element : 56
Please enter the Value of 3 Element : 70
The Largest Element in this List is :  90``````

## Program to find Largest Number in a List Example 5

This program sorts the list items in Ascending order. Next, we used reverse function to reverse the list items. Lastly, we used index position 0 to print the first element 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)```

Python maximum list number output

``````Please enter the Total Number of List Elements: 5
Please enter the Value of 1 Element : 60
Please enter the Value of 2 Element : 30
Please enter the Value of 3 Element : 90
Please enter the Value of 4 Element : 89
Please enter the Value of 5 Element : 45
The Largest Element in this List is :  90``````

## Python Program to return 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

```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
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)```

Python maximum list number output

``````Please enter the Total Number of List Elements: 5
Please enter the Value of 1 Element : 70
Please enter the Value of 2 Element : 80
Please enter the Value of 3 Element : 120
Please enter the Value of 4 Element : 87
Please enter the Value of 5 Element : 46
The Largest Element in this List is :  120
The Index position of the Largest Element is :  2``````

The User inserted values are
NumList = {70, 80, 120, 87, 46}
largest = NumList = 70

First Iteration – for 1 in range(1, 5) – Condition is true
So, it starts 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
largest = 80
position = 1

Second Iteration: for 2 in range(1, 5) – Condition is true
If (largest < NumList)  =  (80 < 120) – Condition True
largest = NumList
largest = 120
Position = 2

Third Iteration: for 3 in range(1, 5) – Condition is true
If (largest < NumList)  =  (120 < 87) – Condition False
largest = 120
Position = 2

Fourth Iteration: for 4 in range(1, 5) – Condition is true
If (largest < NumList)  =  (120 < 46) – Condition False
largest = 120
Position = 2

Fifth Iteration: for 5 in range(1, 5) – Condition is False
So, it exits from the loop.