Minimum of two numbers in Python (original) (raw)

Last Updated : 29 Nov, 2024

In this article, we will explore various methods to find minimum of two numbers in Python. The simplest way to find minimum of two numbers in Python is by using built-in **min()function.

Python `

a = 7 b = 3 print(min(a, b))

`

**Explanation:

**Let’s explore other different method to find minimum of two numbers:

Table of Content

Using Conditional Statements

Another way to find the minimum of two numbers is by using conditional statements like **if and **else. This approach gives us more control over the logic and is useful when we need to implement custom rules.

Python `

a = 5 b = 10

if a < b: print(a) else: print(b)

`

**Explanation:

Using Ternary Operator

Python also supports a shorthand version of conditional statements known as the ternary operator. It allows us to write concise conditional expressions on a single line.

Python `

a = 7 b = 2 res = a if a < b else b print(res)

`

**Explanation:

Similar Reads