Python min() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in

Definition

In Python, min() returns the smallest item. Call it with one iterable, min([4, 2, 9]), or with two or more separate arguments, min(4, 2, 9).

The optional key function decides what to compare, so you can find the cheapest product or the shortest word while still getting the original item back. If several items tie, the first one is returned. An empty iterable raises ValueError unless you pass default.

min() is a built-in function: it lives in the builtins module, so it is always available without an import.

Syntax

Give it an iterable or several values; add key or default by keyword.

python
smallest = min(iterable, key=None)
smallest = min(a, b, c)
smallest = min(iterable, default=value)
CallWhat it does
min(4, 9, 2)Returns 2.
min("python")Returns "h", the character with the lowest code point.
min(words, key=len)Returns the shortest word.
min([], default=0)Returns 0 instead of raising.

Strings compare by Unicode code point, so uppercase letters sort before lowercase: min("b", "B") is "B".

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

Parameters

ParameterDescription
iterableAn iterable of comparable items (one-argument form).
arg1, arg2, *argsTwo or more values to compare (multi-argument form).
keyOptional, keyword-only. A one-argument function whose result is compared, such as len or str.lower.
defaultOptional, keyword-only, iterable form only. Returned when the iterable is empty.

Return Value

Return ValueDescription
itemThe smallest item itself (not its key value). The first one wins on ties.

Python Examples

Example 1 — Smallest Number, Character, and Word

Call min() with separate arguments, a list of floats, a string, and a list of words.

python
print(min(4, 9, 2, 7))
print(min([3.5, -1.0, 2.25]))
print(min("python"))
print(min(["pear", "Apple", "fig"]))

How It Works

  1. Separate arguments. min(4, 9, 2, 7) compares the four values and returns 2.
  2. Any iterable. A list of floats works the same way; the smallest is -1.0.
  3. Characters by code point. A string is iterable, and "h" has the lowest code point of the letters in "python".
  4. Capitals first. "A" (65) is lower than any lowercase letter, so "Apple" beats "fig".

Example 2 — Cheapest Product and Shortest Word with key

Pass a key function to compare one part of each item while returning the whole item.

python
products = [("laptop", 899), ("mouse", 25), ("monitor", 199), ("cable", 25)]

cheapest = min(products, key=lambda p: p[1])
shortest = min(["banana", "kiwi", "cherry"], key=len)
lowest_ci = min(["pear", "Apple", "fig"], key=str.lower)

print("Cheapest:", cheapest)
print("Shortest word:", shortest)
print("First alphabetically (ignoring case):", lowest_ci)

How It Works

  1. Compare the price. key=lambda p: p[1] makes min() look only at the second element of each tuple.
  2. Ties keep order. mouse and cable both cost 25; the first one in the list, mouse, is returned.
  3. Built-in key functions. key=len compares word lengths, so "kiwi" (4 letters) wins.
  4. Case-insensitive. key=str.lower compares lowercase copies but returns the original "Apple".

Example 3 — Empty Lists, default, and a Dict's Lowest Value

Handle empty input safely and find the dictionary key that has the smallest value.

python
empty = []
print(min(empty, default=None))
print(min(empty, default="no data"))

try:
    min(empty)
except ValueError:
    print("min() of an empty list raises ValueError")

temperatures = {"Mon": 21, "Tue": 17, "Wed": 19}
coldest_day = min(temperatures, key=temperatures.get)
print(coldest_day, temperatures[coldest_day])

How It Works

  1. default for empty input. With nothing to compare, min() returns the default value you supply.
  2. No default, no answer. Without default, an empty list raises ValueError.
  3. Iterating a dict gives keys. min(temperatures) alone would compare the day names alphabetically.
  4. key=dict.get. Comparing temperatures.get(day) finds the day with the lowest reading: Tue at 17.

Frequently Asked Questions

Call min(numbers). For an empty list pass a fallback: min(numbers, default=0).
It is a function applied to each item before comparing. min(words, key=len) compares lengths but returns the word itself.
min() returns the first one it found, in the order of the iterable.
Use min(d, key=d.get). To get both, use min(d.items(), key=lambda kv: kv[1]).
Strings compare by Unicode code point, and uppercase letters have lower code points than lowercase ones. Use key=str.lower to ignore case.

Next: next()

Get the next item from an iterator, with an optional default.

next() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful