Use the builtin function max.

Example: max(2, 4) returns 4.

Just for giggles, there's a min as well...should you need it. :P

Answer from Ashley Grenon on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › maximum-of-two-numbers-in-python
Find the Maximum of two numbers in Python - GeeksforGeeks
Let's explore different ways to find the larger of two numbers. max() function compares two or more values and returns the largest one. It performs the comparison internally and eliminates the need to write explicit conditional statements.
Published: May 18, 2026
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › maximum of two numbers in python
Maximum of Two Numbers in Python - Spark By {Examples}
May 31, 2024 - How to find the maximum of two numbers in Python? You can create a program that takes two integers as input from the user and returns the maximum of the
People also ask

Why does max raise a TypeError?
The values may not be mutually comparable, or the input may contain a type that does not define the ordering you expect.
🌐
pythonpool.com
pythonpool.com › home › tutorials › how to find the maximum of two numbers in python
How to Find the Maximum of Two Numbers in Python
What happens when the values are equal?
max returns the equal value, while a conditional expression can choose the first or second object deliberately.
🌐
pythonpool.com
pythonpool.com › home › tutorials › how to find the maximum of two numbers in python
How to Find the Maximum of Two Numbers in Python
Can I use a conditional expression instead?
Yes. first if first >= second else second is explicit and lets you define the tie behavior.
🌐
pythonpool.com
pythonpool.com › home › tutorials › how to find the maximum of two numbers in python
How to Find the Maximum of Two Numbers in Python
🌐
GeeksforGeeks
geeksforgeeks.org › maximum-of-two-numbers-in-python
Find Maximum of two numbers in Python - GeeksforGeeks
Finding the maximum of two numbers in Python helps determine the larger of the two values. For example, given two numbers a = 7 and b = 3, you may want to extract the larger number, which in this case is 7.
Published: May 9, 2025
🌐
IncludeHelp
includehelp.com › python › find-maximum-of-two-numbers.aspx
Python program to find maximum of two numbers
April 3, 2021 - In the above code, we have taken ... we will use the max() function from python's built-in library. The max() function in Python is used to return the maximum of all the elements passed as arguments....
🌐
Python Pool
pythonpool.com › home › tutorials › how to find the maximum of two numbers in python
How to Find the Maximum of Two Numbers in Python
July 13, 2026 - For two comparable values, Python’s max() communicates the intent directly; validate inputs when the values may not share a meaningful ordering. The simplest way to get the maximum of two numbers in Python is max(a, b). It is short, readable, ...
🌐
Python Examples
pythonexamples.org › python-program-maximum-of-two-numbers
Python - Find Maximum of Two Numbers
To find the maximum of given two numbers in Python, call max() builtin function and pass the two numbers as arguments.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › videos › find-maximum-of-two-numbers-in-python
Find Maximum of two numbers in Python - GeeksforGeeks | Videos
Python has built-in functions like max() that simplify finding the maximum of two numbers.
Published: August 16, 2024
Views: 15K
🌐
YouTube
youtube.com › watch
Find Maximum of two numbers in Python | Python Tutorial - YouTube
Watch Video to understand How to find the maximum between wo numbers with Python program? #pythonessentials #pythontutorial #maximumnumberpython #pythonprogr...
Published: August 27, 2022
🌐
Tutorialspoint
tutorialspoint.com › python › number_max.htm
Python max() Function
The Python max() function is used to retrieve the largest element from the specified iterable. Finding the maximum of two given numbers is one of the usual calculations we perform.
🌐
Python-Fiddle
python-fiddle.com › challenges › maximum-of-two-numbers
Maximum of Two Numbers - Python Challenge
#### Example Usage ```python ... a port of CPython to WebAssembly. Some functionality may not work as expected. Run · def maximum(a, b): """ Returns the maximum of two numbers....
🌐
Sololearn
sololearn.com › en › Discuss › 880317 › a-programe-to-find-the-maximum-of-two-numbers-using-python
A programe to find the maximum of two numbers using python | Sololearn: Learn to code for FREE!
or try: def maxi(x,y): if x==y: return print("The numbers are equal") elif x>=y: return (x) else: return(y) print(maxi(5,5)) 26th Nov 2017, 1:23 AM · Daniel · Answer · Learn more efficiently, for free: Introduction to Python · 7.1M learners ...
🌐
Logicalpython
logicalpython.com › python-program-to-find-maximum-of-two-numbers
Python Program to Find Maximum of Two Numbers – Logical Python
After prompting the user to enter two numbers using the input() function, we compare variable a and b to find the maximum. If ‘a’ is greater than ‘b’, we print “Maximum number is:” a else we print b. ... def find_max(a, b): if (a > b): return a else: return b a = float(input("Please ...
🌐
YouTube
youtube.com › watch
largest of two numbers in python | Max Function - YouTube
#simplesnipcode #pythonprograms #pythoncode #largestoftwonumber #maxfun Largest of two number using max function in python | Using the max function to get ma...
Published: September 3, 2022
🌐
Pyschool
pyschool.ai › home › curriculum › find maximum of two
Find Maximum of Two Python Practice Lesson | PySchool.ai
March 15, 2026 - Use conditional logic (if/else) to compare the two values. Do not use built-in functions like max() in your implementation. ... Implement a function find_max(a, b) that returns the greater of the two numeric inputs.
🌐
PREP INSTA
prepinsta.com › home › python program › find the greatest of two numbers in python
Find the Greatest of Two Numbers in Python
September 28, 2022 - In this method we’ll use Ternary Operator in Python to find the Largest Number among the two input integers.
🌐
YouTube
youtube.com › watch
5.12 Maximum of Two Values - Python - YouTube
Hello Everyone! Ultimately, we would use the predefined function max() to solve a question like this, but we recreated the wheel here to see a variation of t...
Published: January 26, 2017