min

Return the smallest item from one iterable or the smallest of two or more arguments. key can compute the value used for ordering; ties keep the first item encountered.

Syntax

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

Parameters

NameDescription
iterableString | list | tuple | dict
A value whose items can be read one at a time, such as a list or string. For dict, compare keys.
Depends on overload · Positional only
No default
argsAny
Additional positional values when passing two or more arguments.
Depends on overload · Variadic
No default
defaultAny
Value returned when the single iterable is empty. Only valid with one iterable argument.
Depends on overload · Keyword only
Default: -
keyCallable?
A function called with each item; compare its result instead of the item. None compares items directly.
Optional · Keyword only
Default: None

Returns

Any — The original smallest item, or default for empty input. Empty input without default, or values that cannot be compared, raises an error.

Example

# Pick the lowest score, with a safe empty-list fallback
best = min([0.9, 0.7, 0.85])
fallback = min([], default="none")
closest = min([12, -5, 7], key=lambda value: abs(value))
text(str(closest))