Languages
[Edit]
EN

Python - max value in an array

0 points
Created by:
Haris65
536

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

Alternative titles

  1. Python - how to find maximum value in an array
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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