Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Function

min

Returns the smallest item from an iterable or the smallest among multiple arguments. Use key for derived comparisons and default to handle an empty iterable.

Since
3.4

How it works

With one positional argument, min() consumes an iterable; with multiple positional arguments, it compares those values directly. The optional key function supplies comparison values, default supplies a result for an empty iterable, and ties return the first minimum encountered.

Syntax

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

Parameters

NameTypeDescription
iterable / arg1iterable or objectThe iterable to search, or the first value in the multi-argument form.
arg2, ...argsobjectAdditional values compared in the multi-argument form.
keycallable or NoneOne-argument function that supplies ordering values.
defaultobjectFallback returned when the iterable is empty.

Returns

The smallest item, or the smallest positional argument; with default, the fallback object for an empty iterable.

Key points

  • min() finds the least item in an iterable or the least among two or more supplied arguments.
  • The single-argument form is intended for an iterable such as a list, tuple, string, or generator.
  • Passing separate values makes min() compare those values directly.
  • Use key to compare items through a derived value, similarly to list.sort().
  • Use default to define the result for an empty iterable.
  • For equal minima, min() has stable first-match behavior consistent with other ordering tools.

Common mistakes

  • An empty iterable raises ValueError unless default is supplied.
  • When several items share the minimum comparison value, min() preserves the iterable's first such item.

Example: Find the lowest-scoring entry

scores = {"Ada": 91, "Linus": 87, "Grace": 95}
lowest_name = min(scores, key=scores.get)
print(lowest_name)  # Linus

Selects the name whose mapped score is smallest.

When to use it

Find a minimum directly

Choose the least numeric or lexicographic value from a collection.

Compare by a derived value

Select the object with the smallest field or computed score.

Provide an empty-input fallback

Avoid an exception when no candidates are available.

Keep the first minimum

Resolve ties predictably while scanning ordered input.

Interview questions

QHow does min() interpret its positional arguments?

With one positional argument, min() expects an iterable and returns its smallest item. With two or more positional arguments, it returns the smallest positional argument.

Follow-up: How can min() choose by a derived attribute? Pass a one-argument key function, such as key=len for shortest strings.

QWhat is the purpose of key?

key receives each candidate and provides the value used for ordering. The candidate itself, rather than its key value, is returned.

Follow-up: What happens when key is omitted? Candidates are compared directly using their ordering behavior.

QWhen should default be used?

default is returned when the supplied iterable is empty. Without default in that situation, min() raises ValueError.

Follow-up: Does default apply when multiple positional arguments are supplied? No; that form compares arguments directly, while default belongs to the iterable form.

  • max
  • sorted
  • list.sort
  • heapq.nsmallest

Source: Built-in Functions. Checked 2026-10-15.