max(iterable, *[, key, default])
max(arg1, arg2, *args[, key])
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.
- 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.
- arg1, arg2, *args: Values to extract the highest from.
This example calculates the maximum value of an iterator:
m = [1, 4, 2, 7, 3]
print(max(m))
In this other example we include several values as arguments:
print(max("a", "f", "c", "h"))