The min function
The min
function returns the minimum number from a group of numbers specified in the parameters. You can specify a group of numbers by listing them separated by commas, or a sequence: list, tuple, set.
Syntax
min(a group of numbers or a sequence)
Example
Let's derive the minimum number from a group of numbers:
num1 = 2
num2 = 5
num3 = 10
print(min(num1, num2, num3))
Result of code execution:
2
Example
Now let's find the minimum number from the group of negative numbers:
num1 = -1
num2 = -3
num3 = -6
print(min(num1, num2, num3))
Result of code execution:
-6
Example
The function also works with lists. Let's find the minimum number by passing a list to the min
function parameter:
lst = [10, 5, 4]
print(min(lst))
Result of code execution:
4
Example
Let's use the function to find the minimum number in a tuple:
tlp = (-2, 6, 9)
print(min(tlp))
Result of code execution:
-2