Python 3 reference · Built-in Functions

Python min() Function

Return the smallest item in an iterable, or the smallest of several arguments. Supports a key function and a default.

Python 3 Since 3.0

Syntax

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

Parameters

ParameterDescription
iterable / args One iterable, or two or more values.
key optional A function that returns the value to compare. Default: None
default optional Returned when the iterable is empty.

Return value

The smallest item.

Examples

Basic useTry it yourself
print(min(3, 9, 4))
print(min([2.5, 7.1, 0.3]))

Output

3
0.3
Compare by a keyTry it yourself
cities = {"Oslo": 7.2, "Cairo": 22.1, "Lima": 19.4}
print(min(cities, key=cities.get))
print(min(["pear", "fig", "banana"], key=len))

Output

Oslo
fig
Defaults and clampingTry it yourself
print(min([], default=None))
value = 140
print(max(0, min(value, 100)))  # clamp to the range 0–100

Output

None
100

Version history

VersionChange
Python 3.0Added
Python 3.4Added the default parameter.
Python 3.8key can be None.