Languages
[Edit]
EN

Python - min() method example

0 points
Created by:
Keisha-Acosta
380

The min() function returns the smallest number from given numbers.

x = min(2, 5)
print(x)  # 2

print(min(1, 2))  # 1
print(min(1.5, 2.0))  # 1.5

1. Documentation

Syntax
min(x1, x2, ... , xN)

or

min(iterable)
Parametersx1x2xN - values to compare
Result

Minimal number value.

It returns TypeError if at least one of the provided values is not a number.

Descriptionmin is a method that takes number arguments and returns the smallest one value.

2. Getting min value from array examples

2.1. With min() method

array = [3, 2, 7, 5]

print(min(array))  # 2

2.2. By comparing all the elements in the array

import math


def min_value(array):
    result = math.inf

    for item in array:
        if item < result:
            result = item

    return result


numbers = [2, 3, 8, 1, 5]

print(min_value(numbers))  # 1

References

  1. Maxima and minima - Wikipedia

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join