EN
Python - min() method example
0 points
The min()
function returns the smallest number from given numbers.
xxxxxxxxxx
1
x = min(2, 5)
2
print(x) # 2
3
4
print(min(1, 2)) # 1
5
print(min(1.5, 2.0)) # 1.5
Syntax |
xxxxxxxxxx 1 min(x1, x2, ... , xN) or xxxxxxxxxx 1 min(iterable) |
Parameters | x1 , x2 , xN - values to compare |
Result |
Minimal It returns |
Description | min is a method that takes number arguments and returns the smallest one value. |
xxxxxxxxxx
1
array = [3, 2, 7, 5]
2
3
print(min(array)) # 2
xxxxxxxxxx
1
import math
2
3
4
def min_value(array):
5
result = math.inf
6
7
for item in array:
8
if item < result:
9
result = item
10
11
return result
12
13
14
numbers = [2, 3, 8, 1, 5]
15
16
print(min_value(numbers)) # 1