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.
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. |
Returns
The largest item.
Try it
Run it and change it
scores = [14, 9, 21] print(max(scores))
Worth knowing
- Safe default:
max([], default=0)returns0without raising aValueError.