Skip to main content

min()

The min() function in Python is a built-in function that returns the smallest item in an iterable (such as a list, tuple, or string) or among multiple arguments. It can also accept an optional key function to specify a custom comparison logic for finding the smallest item.

Parameter Values

Parameter Description
iterable

An iterable (list, tuple, set, etc.) containing the elements to compare and find the minimum value.

default

An optional parameter specifying the value to return if the iterable is empty.

*iterables

Optional additional iterables to compare values from, allowing for finding the minimum value among multiple iterables.

Return Values

The min() function can return any data type that is present in the iterable passed to it.

How to Use min() in Python

Example 1:

The min() function returns the smallest item in an iterable or the smallest of two or more arguments.

min(2, 5, -1, 10, 3)
Example 2:

The min() function can also take a key function to specify a custom comparison.

numbers = [10, 25, 5, 30]
min_num = min(numbers, key=lambda x: x%10)
Example 3:

When used with strings, min() returns the item with the smallest Unicode code point value.

names = ['Alice', 'Bob', 'Charlie', 'Zara']
min_name = min(names)