What is max() in Python?
The max() method in Python returns the largest value from an iterable object.
Syntax
This method is declared as follows:
Parameter and return value
The max() method takes one mandatory parameter that is an iterable object. This iterable object can be a list or a tuple of integers, floating point numbers, strings or characters.
The return value of this function is the greatest value among other values, depending on the argument type.
For instance, in a list of integers, max() returns the largest integer; in a list of strings, it returns the string which has the maximum rank, alphabetically.
Example
In the example below, the max() method returns the largest value from the list of integers, floating point numbers, and strings.
# List of integersint_list = [2, 7, 3, 9]print(max(int_list))# List of floating point numbersfloat_list = [12.1, 7.2, 3.5, 9.9]print(max(float_list))# List of stringsstr_list = ["xyz", "abcf", "abd", "ghij"]print(max(str_list))