Club.noww.in
If you want the smallest value in Python, the Python min function does exactly that. It takes an iterable, or two or more values, and gives you back the smallest one.
print(min([8, 3, 5])) # 3In this tutorial, I’ll take min() through its syntax and five examples: lists and arguments, a key function, dictionaries, empty lists and min() with max(). I ran each one in Python 3.12.5 in Command Prompt.
Python min() Syntax
min(iterable, /, *, key=None) min(iterable, /, *, default, key=None) min(arg1, arg2, /, *args, key=None)| iterable | Yes (form 1-2) | none | Any iterable: list, tuple, dict, generator |
| arg1, arg2, *args | Yes (form 3) | none | Two or more separate values to compare |
| key | No | None | Function that returns the value to compare |
| default | No | none | Returned if the iterable is empty |
Return value: the smallest item itself, not its position. If several items tie, you get the first one. An empty iterable with no default raises ValueError.
Note: key and default are keyword-only. The *args form works like *args in Python functions.
When to Use min() in Python
- Finding the lowest price, score or temperature in a list
- Picking the record with the smallest field, like the cheapest order
- Capping a value at an upper limit together with max()
For loop and sorting approaches, see finding the largest and smallest numbers in Python.
Example 1: Find the Smallest Number in a List with min()
Let me start with a week of morning temperatures, three numbers and three US cities:
temps = [41, 38, 45, 36, 39] print(min(temps)) print(min(72, 58, 64)) print(min("Denver", "Austin", "Boston"))Output:
36 58 Austin
A list, separate numbers and strings.How does this work? the list gave 36 and the arguments gave 58. Python compares strings letter by letter, so Austin wins. More in comparing strings in Python.
Example 2: Find the Cheapest Item with a min() key Function
A key function tells min() what to compare, like each product’s price:
products = [ {"sku": "MUG-12", "price": 14.99}, {"sku": "CAP-07", "price": 9.99}, {"sku": "TEE-03", "price": 9.99}, ] cheapest = min(products, key=lambda p: p["price"]) print(cheapest)Output:
{'sku': 'CAP-07', 'price': 9.99}
The first $9.99 product wins.How does this work? the lambda compared prices only. CAP-07 and TEE-03 both cost $9.99, so the first one in the list came back.
Pro Tip: new to lambdas? Read how to use lambda functions in Python.
Example 3: How Do You Get the Key with the Minimum Value in a Dictionary?
min() on a dictionary looks at the keys. Pass key=sales.get to compare the values:
sales = {"Texas": 18450, "Ohio": 23100, "Oregon": 9320} print(min(sales)) print(min(sales, key=sales.get)) state, total = min(sales.items(), key=lambda kv: kv[1]) print(f"{state}: ${total:,.2f}")Output:
Ohio Oregon Oregon: $9,320.00
Alphabetical key vs lowest sales.How does this work? plain min(sales) returned Ohio, the first key alphabetically. key=sales.get compared sales and picked Oregon, and .items() gave both parts.
To search the other way, read finding a dictionary key by value.
Example 4: Use min() on an Empty List with default
Filtered data can come back empty, and default returns a fallback instead of crashing:
refunds = [] print(min(refunds, default=0.0)) readings = [-1, 0, 7, 3, -1, 12] valid = min((r for r in readings if r > 0), default=None) print(valid)Output:
0.0 3How does this work? the empty refunds list returned 0.0. The generator kept only positive readings, so the answer was 3.
Or test the list first: checking if a list is empty in Python.
Example 5: Use min() with max() and index() in Python
In Python, min() pairs nicely with max() and list.index():
readings = [72.4, 68.1, 75.9, 66.3, 70.2] low = min(readings) print(low, max(readings)) print("Index:", readings.index(low)) def clamp(value, lo, hi): return max(lo, min(value, hi)) print(clamp(105, 60, 90), clamp(45, 60, 90))Output:
66.3 75.9 Index: 3 90 60How does this work? readings.index(low) found 66.3 at position 3. In clamp(), min() caps the top and max() lifts the bottom, so 105 became 90 and 45 became 60.
Also see the Python max() function and getting the index of the minimum element.
Common Mistakes with Python min()
These are the Python min() errors I run into most:
try: min([]) except ValueError as err: print("1. ValueError:", err) try: min([25, "10", 7]) except TypeError as err: print("2. TypeError:", err) try: min(42) except TypeError as err: print("3. TypeError:", err) nan = float("nan") print("4.", min([nan, 4, 2]), min([4, nan, 2]))Output:
1. ValueError: min() iterable argument is empty 2. TypeError: '<' not supported between instances of 'str' and 'int' 3. TypeError: 'int' object is not iterable 4. nan 2
Three errors and a silent NaN surprise.- Empty data: add default=.
- Mixed str and int can’t be compared.
- One number isn’t iterable; pass a list.
- NaN’s position changes the result.
Filter NaN out first: how to check for NaN in Python.
Wrapping Up the Python min() Function
Python’s min() function returns the smallest value from an iterable or from separate arguments. Use key to choose what gets compared and default for empty data. In pandas, a column’s .min() method does the same job.
Next, browse more Python built-in functions and methods.
Keep practicing with these:
- find the smallest element in a NumPy array
- find the maximum value in a Python dictionary
- find the closest value in a Python list
- get the average of a list in Python
Python min() Function FAQs
Does min() work on strings in Python?
Yes. A list of strings uses alphabetical order, with uppercase before lowercase.
Is min() faster than sorting?
Yes. It makes one pass over the data, so it beats sorted(data)[0].
Does min() work with None values?
No. Comparing None with a number raises TypeError; filter Nones out first.
How do I get the 3 smallest values in Python?
Use heapq.nsmallest(3, data), or sorted(data)[:3].
Where can I read the full min() reference?
All three signatures are listed in min() in the Python docs.











English (US)