user
How to compute the min between two variables in Python?
alphonsio

The best option to compute the minimum value batween two variables is to use the built-in min() function:

print (min(6,5)) # Output 5

In Python, you can compute the minimum between two variables easily using the built-in min() function.

Example:

a = 10
b = 5

result = min(a, b)
print(result)

Output:

5

How it works:

  • min(a, b) returns the smaller of the two values.

  • You can also pass more than two values:

    min(3, 8, 1, 9)  # returns 1
    

Alternative (using conditional expression):

If you prefer not to use min() (for example, in algorithmic contexts):

result = a if a < b else b