EN
Python - max() method example
0 points
The max()
function returns the highest number from given numbers.
xxxxxxxxxx
1
x = max(2, 5)
2
print(x) # 5
3
4
print(max(1, 2)) # 2
5
print(max(1.5, 2.0)) # 2.0
Syntax |
xxxxxxxxxx 1 max(x1, x2, ... , xN) or xxxxxxxxxx 1 max(iterable) |
Parameters | x1 , x2 , xN - values to compare |
Result |
Maximal It returns |
Description | max is a method that takes number arguments and returns the biggest value. |
xxxxxxxxxx
1
array = [1, 3, 7, 5]
2
3
print(max(array)) # 7
xxxxxxxxxx
1
import math
2
3
4
def max_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(max_value(numbers)) # 8