BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Program to Find Largest Number in a List

Last Updated: June 9, 2019 by Chaitanya Singh | Filed Under: Python Examples

In this tutorial, we will see various Python programs to find the largest number in a List. For example, if the list is [5, 10, 30, 6] then the output of the program should be 30 (the largest number in the given list).

Example 1: Finding largest number in a list using sort() method

In the following program we are using the sort() function to find the largest number in the given list. A list of numbers is given in the program and we are sorting the given list using sort() function, which sorts the list in ascending order. We are then displaying the last element of the list, which is the largest number in the sorted list.

# Python program to find largest number in a list

# A list of numbers is given
lis = [1, 10, 40, 36, 16]

# sorting the given list "lis"
# sort() function sorts the list in ascending order
lis.sort()

# Displaying the last element of the list
# which is the largest number in the sorted list
print("Largest number in the list is:", lis[-1])

Output:
Python Program to find Largest number in a list

Example 2: Finding largest number in a list using max() method

In the following program we are finding the largest number of the list using max() method. The max() method returns the largest element of the list.

# Python program to find largest number in a list
# using max() function

# A list of numbers
lis = [19, 10, 45, 26, 6]

# max() method returns the largest element of the list
print("Largest number of the list is:", max(lis))

Output:
Finding largest number in a list using max() method

Example 3: Finding largest number in a list, where list is provided by user

In the following example we are finding the largest number in the user provided list. In the program, user is asked to enter the number of elements to put in a list, then user enters the elements of the list which are appended to the list using append() method. At the end the largest element is displayed using max() method.

# creating empty list
lis = []

# user enters the number of elements to put in list
count = int(input('How many numbers? '))

# iterating till count to append all input elements in list
for n in range(count):
    number = int(input('Enter number: '))
    lis.append(number)

# displaying largest element
print("Largest element of the list is :", max(lis))

Output:
Finding Largest number in the user provided list

Related Python Examples

  1. Python Program to find Smallest number in a list
  2. Python program to find largest among three numbers
  3. Python program to generate a random number
  4. Python program to find ASCII value of a character

Top Related Articles:

  1. Python Program to Find Largest among Three Numbers
  2. Python Program to Convert Celsius To Fahrenheit and Vice Versa
  3. Python Program to Check if a Number is Positive Negative or Zero
  4. Python Program to Find Factorial of Number
  5. Python Program to Convert Decimal to Hexadecimal

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap