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

pythonmin(a group of numbers or a sequence)

Example

Let's derive the minimum number from a group of numbers:

pythonnum1 = 2
num2 = 5
num3 = 10
print(min(num1, num2, num3))

Result of code execution:

python2

Example

Now let's find the minimum number from the group of negative numbers:

pythonnum1 = -1
num2 = -3
num3 = -6
print(min(num1, num2, num3))

Result of code execution:

python-6

Example

The function also works with lists. Let's find the minimum number by passing a list to the min function parameter:

pythonlst = [10, 5, 4]
print(min(lst))

Result of code execution:

python4

Example

Let's use the function to find the minimum number in a tuple:

pythontlp = (-2, 6, 9)
print(min(tlp))

Result of code execution:

python-2

See also

  • function max,
    which returns the maximum number
  • function abs,
    which returns the absolute value of a number