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
max()accepts any number of values and returns the biggest.min()returns the smallest.- In the second version,
andmeans both comparisons must be true. Ifais at least as big as both others, it is the largest. >=(not>) makes the program work when two numbers are equal: with25, 25, 18it still finds 25.