Skip to content
Built-in Functions

max()

Find the largest item in an iterable.

max(iterable, *, key=None, default=...)

max() returns the largest item in an iterable or the largest of two or more arguments.

Supports custom comparison criteria via the key parameter and fallback values via default on empty iterables.

Parameters

NameDescription
iterableItems to compare.
keyOptional function used to choose how items are compared.
defaultOptional value returned for an empty iterable.

Returns

The largest item.

Try it

Run it and change it
scores = [14, 9, 21]
print(max(scores))

Worth knowing

  • Safe default: max([], default=0) returns 0 without raising a ValueError.

Related entries