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.
Arguments
Parameters
| Name | Description |
|---|---|
| iterable | Items to compare. |
| key | Optional function used to choose how items are compared. |
| default | Optional value returned for an empty iterable. |
Result
Returns
The largest item.
Run it
Try it
Run it and change it
scores = [14, 9, 21] print(max(scores))
Output
Press Run to see what it prints.Worth knowing
- Safe default:
max([], default=0)returns0without raising aValueError.