Return the largest item from one iterable or the largest of two or more arguments.
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=.Behavior / side effects
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.
Execution
- Blocking: Conditional
- Thread safety: Use separate objects per flow
- Parallel execution: Conditional
The operation processes values in the calling flow. A key callable also runs there and may perform waits or side effects; no asynchronous execution is implied.
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)Errors / limitations
No additional limitations documented; follow the parameter and behavior contract above.
Related APIs
None