Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

min()

Returns the input item with the smallest comparison key.

Version: Python 3.14; repository image, production runtime not attested

Syntax

min(iterable, /, *, key=None[, default])
min(arg1, arg2, /, *args, key=None)

Returns the input item with the smallest comparison key.

Ties select the first encountered minimum. A supplied default handles empty input.

The minimum is an original item, not its key. Of lengths 2, 1, 1 the first length-one value is b, so it wins the tie with c. For a single empty iterable the supplied default −1 is returned without passing it through key. With no default an empty input raises ValueError.

a = ["aa", "b", "c"]
assert min(a, key=len) is a[1] and min([], default=-1) == -1
assert min(2, 7, 4) == 2

Examples

print(min(["aa", "b", "c"], key=len))
print(min([], default=-1))

Result

b
-1

The minimum is an original item, not its key. Of lengths 2, 1, 1 the first length-one value is b, so it wins the tie with c. For a single empty iterable the supplied default −1 is returned without passing it through key. With no default an empty input raises ValueError.

Sources