Python Glossary Русский

all Python 3Built-in functionsterm

min

numbers/collections

Returns the smallest item of an iterable, or the smallest of the arguments given. Supports a key function.

Syntax

min(iterable, *, key=None)
min(a, b, ...)

min makes a single O(n) pass, so it beats sorted(...)[0] when you only need one extreme element. Mixed types are not silently ordered: comparing a number with a string raises TypeError, and strings are compared code point by code point, which is why '10' comes out smaller than '9'.

Examples

print(min(3,1,4,1,5))  # → 1
print(min([10,20,5]))  # → 5
print(min('apple','banana','cherry'))  # → apple
print(min([1,2,3], key=lambda x:-x))  # → 3
print(min([], default=0))  # → 0

See also

Open in the full glossarydocs.python.orgReport an inaccuracy