The min()
method in Python returns the smallest value from an iterable object.
This method is declared as follows:
Only one parameter is required in the min()
method. This parameter can be a list or tuple of integers, floating-point numbers, strings, or characters.
The return value of this method depends upon the parameter. If an iterable object of integers is passed into min()
, it returns the smallest integer.
In the case of a list of strings or characters as the argument of the min()
method, the lowest value is returned.
For example, in the first two calls, min()
returns the smallest number from the list. From the list of strings, it returns “abcf” because this sequence is the smallest, alphabetically.
# List of integersint_list = [2, 7, 3, 9]print(min(int_list))# List of floating point numbersfloat_list = [12.1, 7.2, 3.5, 9.9]print(min(float_list))# List of stringsstr_list = ["xyz", "abcf", "abd", "ghij"]print(min(str_list))