Built-in Functions and Types

min()

Select the smallest 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
min(iterable, /, *, key=None)min(iterable, /, *, default, key=None)min(arg1, arg2, /, *args, key=None)

Parameters & Attributes

NameTypeDescription
iterableiterableSingle-argument form; items to compare.
arg1objectFirst candidate in the multiple-argument form.
arg2objectSecond candidate in the multiple-argument form.
argsobjectAdditional positional candidates in that form.
keycallable | NoneKeyword-only function mapping each item to its comparison value.
defaultobjectKeyword-only fallback for an empty iterable; omission means no fallback.

Return Value

object

The smallest original item, or the supplied default if the iterable is empty.

Working Example

Example Snippetpython
locations = [("west", 8), ("east", 3), ("north", 3)]chosen = min(locations, key=lambda row: row[1])print(chosen[0])print(min([], default="none"))
Python Reference