Built-in Functions and Types
max()
Select the largest item using ordinary ordering or an optional comparison key. The result is the original item, not the computed key. When items tie, the first encountered wins. An empty iterable needs default to avoid ValueError; default is unavailable in the multiple-positional-arguments form. Items or computed keys must be mutually orderable.
Formal Syntax & Structure
python syntaxpython
max(iterable, /, *, key=None)max(iterable, /, *, default, key=None)max(arg1, arg2, /, *args, key=None)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| iterable | iterable | Single-argument form; items to compare. |
| arg1 | object | First candidate in the multiple-argument form. |
| arg2 | object | Second candidate in the multiple-argument form. |
| args | object | Additional positional candidates in that form. |
| key | callable | None | Keyword-only function mapping each item to its comparison value. |
| default | object | Keyword-only fallback for an empty iterable; omission means no fallback. |
Return Value
object
The largest original item, or the supplied default if the iterable is empty.
Working Example
Example Snippetpython
locations = [("west", 8), ("east", 12), ("north", 12)]chosen = max(locations, key=lambda row: row[1])print(chosen[0])print(max([], default="none"))