Python Program to Find Largest Number in a List

This article is created to cover some programs in Python, that find and prints largest number (or element) in a given list. Here are the list of programs covered:

Find Largest Number in List without max()

The question is, write a Python program to find largest element in a list using for loop. The program given below is the answer to this question:

nums = []
print("Enter 10 Elements (Numbers) for List: ")
for i in range(10):
  nums.append(int(input()))

large = nums[0]
for i in range(10):
  if large<nums[i]:
    large = nums[i]

print("\nLargest Number is: ")
print(large)

Here is its sample run:

python find largest number in list

Now supply the input say 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 as ten numbers for the list, now press ENTER key to find and print the largest number from the given list of numbers:

find largest number in list python

Find Largest Number in List using max()

The question is, write a program in python that find and prints largest number in a list using max() method. Following program is the answer to this question:

nums = []
print(end="Enter the Size of List: ")
listSize = int(input())

print(end="Enter " +str(listSize)+ " Elements for List: ")
for i in range(listSize):
  nums.append(int(input()))

large = max(nums)
print("\nLargest Number = " + str(large))

Here is its sample run with user input, 5 as size of list and 1, 2, 3, 4, 0 as five elements of list:

find largest element in list python

Python Online Test


« Previous Program Next Program »