min
Find the smallest item of an iterable or the smallest of several arguments.
Python 3.13
min(iterable, *, key=None[, default])
min(arg1, arg2, *args, key=None)- [ ]optional part
- =default value
- *arguments after it by name only
- iterable
- The items to search for the minimum.Iterable
- arg1, arg2, *args
- Two or more values to compare instead of iterable.Any
- key
- A function whose result is used to compare items, such as len; without it, the items themselves are compared.Callable | NoneOptional
- default
- What to return if iterable is empty; works only with iterable.AnyOptional
Return value
The smallest item; raises ValueError for an empty iterable without default.
Examples
Smallest of the arguments
Python 3.13
print(min(1, 2, 3))1
Shortest word
Python 3.13
print(min(['banana', 'kiwi', 'apple'], key=len))kiwi
Default value for an empty list
Python 3.13
print(min([], default=0))0
Details
If several items are equally small, the first of them is returned.
