all Python 3Built-in functionsterm
max
numbers/collections
Returns the largest item of an iterable, or the largest of the arguments given. Supports a key function.
Syntax
max(iterable, *, key=None)
max(a, b, ...)
max raises ValueError on an empty iterable, so pass default whenever the input may be empty. key only changes what is compared — you still get the element back, not the key value, which is how you obtain the dict key with the largest value rather than the value itself. When several items tie for largest, the first one encountered wins.
Examples
print(max(3,1,4,1,5)) # → 5
print(max([10,20,5])) # → 20
print(max('apple','banana','cherry')) # → cherry
print(max([1,2,3], key=lambda x:-x)) # → 1
print(max([], default=0)) # → 0
See also
Open in the full glossarydocs.python.orgReport an inaccuracy