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.
Practical examples
1. With max()
method
array = [1, 3, 7, 5]
print(max(array)) # 7
2. By comparing all the elements in the array
import math
def max_value(array):
result = -math.inf
for item in array:
if item > result:
result = item
return result
numbers = [2, 3, 8, 1, 5]
print(max_value(numbers)) # 8