min() mirrors max() exactly, but for the smallest value: pass a single iterable or several separate arguments, an optional key function to change what 'smallest' means, and an optional default that's returned instead of raising ValueError when an iterable happens to be empty.
1Understanding min()
min() mirrors max() exactly, but for the smallest value: pass a single iterable or several separate arguments, an optional key function to change what 'smallest' means, and an optional default that's returned instead of raising ValueError when an iterable happens to be empty.
min() and max() both resolve ties by returning the FIRST item that achieves the extreme value, which matters when several items compare equal under a key function.
temperatures = [72, 68, 75, 61, 80]
print(min(temperatures))2Practical Example
Here is a real-world application of min() showing how it is used in production Python code.
flights = [{"airline": "A", "price": 320}, {"airline": "B", "price": 275}]
cheapest = min(flights, key=lambda f: f["price"])
print(cheapest["airline"])3Best Practices
Follow these guidelines when working with min():
1. Use key= to find the item with the smallest computed property instead of manually tracking a running minimum in a loop
2. Pass default=... for iterables that might be empty at runtime
3. Combine min() and max() to compactly compute a range from a single collection
Tip: min() and max() both resolve ties by returning the FIRST item that achieves the extreme value, which matters when several items compare equal under a key function.
temperatures = [72, 68, 75, 61, 80]
print(min(temperatures))