max

Full name
max
Library
Built-in
Syntax

max(iterable, *[, key, default])

max(arg1, arg2, *args[, key])

Description

The max function returns the maximum value of an iterable, or the maximum value of two or more arguments. If only one positional argument is specified, it must be an iterable and the function will return its highest element. If two or more positional arguments are included, the function will return the highest argument. If multiple maximum values are found, the first one found is returned.

Parameters
  • iterable: Iterable whose highest value we want to obtain.
  • key: (Optional) argument that specifies the single input argument function to use to determine the highest value.
  • default: Value to return if the iterable is empty. If the iterable is empty and this argument is not specified, the function returns an error of type ValueError.
  • arg1arg2, *args: Values to extract the highest from.
Examples

This example calculates the maximum value of an iterator:

m = [1, 4, 2, 7, 3]
print(max(m))

Function max. Example of use

 

In this other example we include several values as arguments:

print(max("a", "f", "c", "h"))

Function max. Example of use

 

Submitted by admin on Sun, 01/20/2019 - 17:55