Return the largest item from one iterable or the largest of two or more arguments. key can compute the value used for ordering; ties keep the first item encountered.
Syntax
max(iterable, /, *, key=None) | max(iterable, /, *, default, key=None) | max(arg1, arg2, /, *args, key=None)Parameters
| Name | Description |
|---|---|
iterableString | list | tuple | dict | Single iterable input. Dictionaries compare keys. Depends on overload · Positional only No default |
argsAny | Additional positional values when passing two or more arguments. Depends on overload · Variadic No default |
defaultAny | Value returned when the single iterable is empty. Only valid with one iterable argument. Depends on overload · Keyword only Default: - |
keyCallable? | One-argument callable used to compute comparison keys. Optional · Keyword only Default: None |
Returns
Any — The original largest item, or default when an empty iterable is provided with default=.Example
# Pick the highest score, with a safe empty-list fallback
peak = max([0.9, 0.7, 0.85])
fallback = max([], default="none")
longest = max(["a", "team", "go"], key=lambda value: len(value))
text(longest)