Languages
[Edit]
EN

Python - max value in an array

0 points
Created by:
Haris65
386

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

See also

  1. Python - max() method example

  2. Maxima and minima - Wikipedia

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join