CKTIS / Python
max()
Selects the input item with the largest comparison key.
Version: Python 3.14; repository image, production runtime not attested
Syntax
max(iterable, /, *, key=None[, default])
max(arg1, arg2, /, *args, key=None)Selects the input item with the largest comparison key.
Ties return the first maximal item. A supplied default handles an empty iterable.
Selects the original input item with the largest key, or the largest input itself when no key function is given. Both aa and bb have maximum length two, so the first, aa, wins. Only the single-iterable form accepts a default for empty input; without it empty input raises ValueError.
a = ["aa", "bb", "c"]
assert max(a, key=len) is a[0] and max([], default=0) == 0
assert max(2, 7, 4) == 7
Examples
print(max(["aa", "bb", "c"], key=len))
print(max([], default=0))
Result
aa 0
Selects the original input item with the largest key, or the largest input itself when no key function is given. Both aa and bb have maximum length two, so the first, aa, wins. Only the single-iterable form accepts a default for empty input; without it empty input raises ValueError.