How to Find the Largest Number in a List Using Python

To find the largest number in a list using Python, pass the list to the built-in max() function. max([4, 17, 9]) returns 17. It checks each item once, so it’s the fastest option:

numbers = [4, 17, 9]
print(max(numbers))   # 17

I ran each snippet here on Python 3.12.5 in a Windows Command Prompt and pasted the printed results as they appeared.

In this tutorial, we’ll find the largest number in a list using Python with max(), a loop, sorting, text values and top-N picks.

Find the largest number in a list with max()

Here are five months of 2026 sales. max() picks the biggest, and default= stops an empty list from crashing:

sales = [1249.99, 875.50, 2310.75, 640.00, 1980.25]   # Jan-May 2026, USD

print("Largest sale:", f"${max(sales):,.2f}")
print("Empty list:", max([], default=None))

Output:

Largest sale: $2,310.75
Empty list: None
Command Prompt output of Python max() returning the largest sale from 2026 USD amounts
max() prints the largest sale, and the empty list returns None instead of a ValueError.

Without default, max([]) raises a ValueError. The key and default arguments are covered in the Python max() function guide.

Find the largest number in a list without max()

Interviews and homework often ban max(). Start with the first item, then replace it whenever a bigger number shows up:

temps = [72, 85, 91, 78, 88, 94, 81]      # Phoenix highs, July 2026, F

largest = temps[0]
for t in temps[1:]:
    if t > largest:
        largest = t
print("Hottest day:", largest, "F")

Output:

Hottest day: 94 F

That’s exactly what max() does inside. To track the smallest value in the same pass, see finding the largest and smallest numbers in Python.

Get the largest number by sorting the list

Sorting puts the biggest number last, at index -1. sorted() returns a new list; .sort() changes yours:

scores = [88, 92, 79, 95, 84]

print(sorted(scores)[-1])          # new sorted copy, original untouched
print(scores)

scores.sort()                      # sorts in place, changes the list
print(scores[-1], scores)

Output:

95
[88, 92, 79, 95, 84]
95 [79, 84, 88, 92, 95]

Only sort when you need the order anyway; it’s far more work. More options are in sorting an array in Python.

How do you find the largest number in a list of strings?

Numbers read from a file often arrive as text. Strings compare letter by letter, so "9.50" beats "1200.00". Add key=float to compare their numeric values:

prices = ["19.99", "149.00", "9.50", "1200.00"]    # read from a CSV file

print("Text compare :", max(prices))               # compares like words
print("Number compare:", max(prices, key=float))   # compares as numbers

mixed = [10, "25", 7]
try:
    max(mixed)
except TypeError as err:
    print("TypeError:", err)

Output:

Text compare : 9.50
Number compare: 1200.00
TypeError: '>' not supported between instances of 'str' and 'int'
Command Prompt output of Python max() on price strings with and without key=float, plus a TypeError for a mixed list
The plain max() returns the wrong price, key=float returns the real largest, and the mixed list raises a TypeError.

You can use the same key trick for the max value in a Python dictionary.

Find the top N and second largest numbers in a list

heapq.nlargest() returns the biggest N values. For the second largest, set() drops duplicates so a tie doesn’t count twice:

import heapq

donations = [250.00, 75.50, 1000.00, 500.00, 1000.00, 320.25]

print("Top 3:", [f"${d:,.2f}" for d in heapq.nlargest(3, donations)])
print("Second largest:", f"${sorted(set(donations))[-2]:,.2f}")
print("Index of largest:", donations.index(max(donations)))

Output:

Top 3: ['$1,000.00', '$1,000.00', '$500.00']
Second largest: $500.00
Index of largest: 2

list.index() returns the first position of the largest value. Ties and other approaches are in finding the index of the maximum value in a list.

Which way to find the largest number is fastest?

I timed all three on one million random floats:

import random, timeit

random.seed(2026)
data = [random.random() for _ in range(1_000_000)]

def loop():
    big = data[0]
    for x in data:
        if x > big:
            big = x
    return big

for name, fn in [("max(data)", lambda: max(data)), ("for loop", loop),
                 ("sorted(data)[-1]", lambda: sorted(data)[-1])]:
    best = min(timeit.repeat(fn, number=3, repeat=3)) / 3 * 1000
    print(f"{name:<17} {best:7.1f} ms")
print("Same answer:", max(data) == loop() == sorted(data)[-1])

Output:

max(data)             6.3 ms
for loop             10.8 ms
sorted(data)[-1]    193.6 ms
Same answer: True
Command Prompt output timing Python max(), a for loop and sorted() for the largest number in a million-item list
All three return the same number; max() finishes first, the loop is slower, and sorted() is the slowest by far.

Milliseconds vary between runs, but the order doesn’t. For NumPy arrays, use np.max() instead, as shown in finding the maximum value in a Python array.

Ready for a related problem? These are good next reads:

Frequently asked questions

How do I find the largest number in a list in Python?

Call max(my_list). It returns the biggest value and leaves the list unchanged.

How do I find the largest number without using max()?

Loop over the list and keep the biggest value seen so far.

Why does max() raise a ValueError?

The list is empty. Pass a fallback such as max(nums, default=None).

Why does max() return the wrong number for a list of strings?

Strings compare character by character. Use max(values, key=float) to compare them as numbers.

How do I get the second largest number in a list?

Use sorted(set(nums))[-2], which skips duplicates of the largest value.

Where is max() documented?

See max() in the Python docs.