![]() |
VOOZH | about |
Given two numbers, the task is to find the smaller (minimum) number between them. For Example:
Input: a = 7, b = 3
Output: 3
Let's explore different methods to find the minimum of two numbers in Python.
Python provides the built-in min() function, which compares multiple values and returns the smallest one.
9
Explanation: min() function compares a and b and returns the smaller value, which is 9.
The ternary operator allows us to write a conditional expression in a single line and return a value based on a condition.
9
Explanation: condition a < b is checked. Since it is false, the expression returns b, which is 9.
We can use an if-else statement to compare the two numbers and print the smaller one.
9
Explanation: condition a < b evaluates to True, so a is printed. Therefore, the output is 9.