Chapters
Python114 chapters

ReferenceBuilt-in functions

max()

The largest item, optionally judged by a key function.

Signature

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

Parameters

NameMeans
iterableor several separate arguments
keycalled on each item to decide the ordering
defaultreturned when the iterable is empty

Returns

The item itself, not the key's value.

Example

Python
print(max([3, 1, 4]))
print(max("apple", "pear", key=len))
print(max([], default="nothing"))

Output

4
apple
nothing

See also