Python built-in Method - min()

The min() function is a built-in Python method that returns the smallest element in an iterable, such as a list, tuple, or set. It can also be used with multiple arguments, where it will return the smallest of all the arguments.

The syntax for the min() function is as follows:

r‮:ot refe‬theitroad.com
min(iterable, *iterables[, key, default])
  • iterable: The iterable object from which the minimum value is to be obtained.
  • *iterables: Optional additional iterable objects to compare with the first iterable. If multiple iterables are provided, then the minimum of all elements from these iterables will be returned.
  • key: An optional function that will be applied to each element of the iterable(s) before comparison, and based on which the minimum value is determined.
  • default: An optional value that will be returned if the iterable is empty.

Here's an example usage of the min() function:

>>> lst = [3, 5, 1, 8, 2]
>>> min(lst)
1

In the above example, the min() function returns the smallest element of the list lst, which is 1.

>>> set1 = {7, 5, 3}
>>> set2 = {9, 2, 8}
>>> min(set1, set2)
2

In the above example, the min() function returns the smallest element of the two sets set1 and set2, which is 2.