ReferenceBuilt-in functions
max()
The largest item, optionally judged by a key function.
Signature
max(iterable, key=None, default=...)Parameters
| Name | Means |
|---|---|
iterable | or several separate arguments |
key | called on each item to decide the ordering |
default | returned when the iterable is empty |
Returns
The item itself, not the key's value.
Example
Python
print(max([3, 1, 4]))
print(max("apple", "pear", key=len))
print(max([], default="nothing"))Output
4 apple nothing