PythonMastery

Find the largest of three numbers in Python

Find the biggest of three numbers with the built-in max(), and with if / elif comparisons to see how the logic works.

Python's built-in max() does this in one call. Writing the comparisons yourself is good practice, so this page shows both.

The program

python
a, b, c = 10, 25, 18

print("Largest:", max(a, b, c))
output
Largest: 25

The same thing with if and elif

python
a, b, c = 10, 25, 18

if a >= b and a >= c:
    largest = a
elif b >= a and b >= c:
    largest = b
else:
    largest = c

print("Largest:", largest)
output
Largest: 25

How it works

Learn the idea: Control Flow: Conditionals, Operators & Expressions