EN
Python - max value in an array
0 points
This article will show you how to find the maximum value in an array in Python.
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