Python min() function
Return the smallest item.
Syntax
min(iterable, *, key=None, default=...) / min(a, b, ...)
The mirror image of max, with the same key and default options.
Parameters
| iterable | the items to compare |
| key | a function that gives the value to compare |
| default | returned if the iterable is empty |
Return value
the smallest item
Example
Code
print(min([3, 9, 2])) print(min("python")) # smallest character prices = {"tea": 3.0, "coffee": 4.5, "juice": 6.0} print(min(prices, key=prices.get)) # the cheapest item's name print(min([], default=None))
Output
2 h tea None
Related
Learn it step by step in the free lesson More Functions, with exercises that check your answers.