EN
Python - min() method example
0
points
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 |
or
|
| 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. |
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