transformation

min()

Returns the smallest item in an iterable or the smallest of two or more arguments. Supports a key function for custom comparison.

min(iterable, *, key=None, default=...)  |  min(arg1, arg2, *args, *, key=None)

Parameters

Parameter Purpose
key Function extracting a comparison key
default Value returned when iterable is empty (else ValueError)

Examples

min([3, 1, 4, 1, 5])

Returns 1

min(['abc', 'de'], key=len)

Returns 'de'

min([], default=0)

Returns 0 (no ValueError)

Gotcha

Passing an empty iterable without default raises ValueError. Mixing incomparable types (int vs str) raises TypeError.

Related built-ins

← All Python built-ins