Python min() Function Explained

min() is a built-in Python function that returns the smallest item. You can use it with a single iterable, like a list or tuple, or with multiple values separated by commas.

This page explains what min() does, its main syntax forms, and the common mistakes beginners make when using it.

Quick example

numbers = [5, 2, 9, 1]
print(min(numbers))

print(min(5, 2, 9, 1))

Output:

1
1

Use min() with one iterable like a list, or with multiple values separated by commas.

What min() does

  • min() returns the smallest item
  • It can compare numbers, strings, and other comparable values
  • It is a built-in Python function
  • This page explains the function itself, not task-based use cases

Main syntax forms

Here are the main ways to use min():

min(iterable)
min(value1, value2, value3, ...)
min(iterable, key=...)
min(iterable, default=...)

min(iterable)

Use this form when you have one collection of values.

numbers = [8, 3, 12, 1]
print(min(numbers))

Output:

1

min(value1, value2, value3, ...)

Use this form when you want to compare separate values directly.

print(min(8, 3, 12, 1))

Output:

1

min(iterable, key=...)

Use key when you want Python to compare items using a custom rule.

words = ["pear", "kiwi", "banana"]
print(min(words, key=len))

Output:

kiwi

Python compares the lengths of the strings, but it returns the original item, not the length.

If you are not familiar with len(), see the len() function explained.

min(iterable, default=...)

Use default when the iterable might be empty.

numbers = []
print(min(numbers, default=0))

Output:

0

This avoids a ValueError when there is no item to return.

Using min() with numbers

min() works with integers and floats. It returns the lowest numeric value.

scores = [88, 72, 95, 60]
print(min(scores))

Output:

60

It also works with decimal values:

prices = [19.99, 5.49, 12.75]
print(min(prices))

Output:

5.49

This is useful for things like:

  • scores
  • prices
  • measurements
  • ages

Using min() with strings

min() can also compare strings. It uses character order, which is similar to alphabetical order.

words = ["banana", "apple", "cherry"]
print(min(words))

Output:

apple

Be careful with uppercase and lowercase letters. They are not treated the same.

words = ["banana", "Apple", "cherry"]
print(min(words))

Output:

Apple

This may look surprising at first. Python compares characters by their internal order, so mixed letter case can change the result.

If you need all items in order instead of just the smallest one, see sorted() explained.

Using min() with a key function

The key argument changes how items are compared.

Important points:

  • key changes the comparison rule
  • min() still returns the original item
  • This is useful for custom comparisons

Find the shortest string

words = ["elephant", "cat", "giraffe"]
print(min(words, key=len))

Output:

cat

Find the dictionary with the smallest value

students = [
    {"name": "Ana", "score": 85},
    {"name": "Ben", "score": 72},
    {"name": "Cara", "score": 90}
]

lowest = min(students, key=lambda student: student["score"])
print(lowest)

Output:

{'name': 'Ben', 'score': 72}

Here, Python compares the "score" values, but it returns the full dictionary.

Using default with empty iterables

An empty iterable has no smallest item, so this causes an error:

numbers = []
print(min(numbers))

Output:

ValueError: min() arg is an empty sequence

To avoid that, use default:

numbers = []
print(min(numbers, default=None))

Output:

None

This is helpful when your list may be empty and you want a safe fallback value.

Remember:

  • default works only when min() gets one iterable argument
  • It does not work with min(3, 5, default=0)

If you want help with this error, see ValueError in Python: causes and fixes.

Common errors and limits

Here are the most common problems with min().

Empty list without default

This raises a ValueError:

items = []
print(min(items))

Fix it by:

  • checking that the iterable is not empty first
  • or using default
items = []
print(min(items, default="no items"))

Mixed types

In Python 3, values must usually be comparable to each other. This often fails:

data = [10, "20", 5]
print(min(data))

Output:

TypeError

That happens because Python cannot directly compare integers and strings here.

A simple fix is to convert everything to the same type before calling min().

data = [10, "20", 5]
numbers = [int(x) for x in data]
print(min(numbers))

Output:

5

For more help with type-related problems, see this guide to TypeError.

String comparisons may not match your expectation

If strings have mixed uppercase and lowercase letters, the result may not match normal dictionary order.

words = ["zebra", "Apple", "monkey"]
print(min(words))

Output:

Apple

If needed, compare them in lowercase:

words = ["zebra", "Apple", "monkey"]
print(min(words, key=str.lower))

Output:

Apple

Here Python compares using lowercase versions, but still returns the original string.

When to use min()

Use min() when:

  • you need the smallest item quickly
  • you want to compare values with a custom rule using key
  • you want one result, not a full sorted list

Use sorted() if you need all items in order.

Use max() if you want the largest item instead.

Common mistakes

Beginners often run into these problems:

  • Passing an empty list or tuple to min() without using default
  • Mixing incompatible types such as integers and strings
  • Expecting min() on strings to ignore uppercase and lowercase differences
  • Forgetting that key affects comparison but min() still returns the original item
  • Using default in the wrong syntax form with multiple separate arguments

If you are debugging code that uses min(), these quick checks can help:

print(type(data))
print(data)
print(len(data))
print(min(data))
print(min(data, default=None))
print(min(words, key=len))

Use them carefully. For example, print(min(data)) will still fail if data is empty or contains incompatible types.

FAQ

What does min() return in Python?

It returns the smallest item from an iterable, or the smallest value from multiple arguments.

Can min() work with strings?

Yes. It compares strings using character order, which is similar to alphabetical order but affected by letter case.

What happens if the list is empty?

min() raises a ValueError unless you use the default argument.

What does key do in min()?

key tells Python how to compare items. For example, key=len compares strings by length.

What is the difference between min() and sorted()?

min() returns only the smallest item. sorted() returns a new sorted list of all items.

See also