Python max() function

Published February 16, 2022

When working with strings or lists, you might need to determine the maximum and minimum values. For instance, in a student score list, you may want to identify the highest-scoring student. In Python, we use the max() function to get the highest value in a list or string.

The max() method returns the largest value iterable, such as the largest list.  If the list consists only of strings, the max() function will return the last item alphabetically.

Syntax
Let's look at the syntax of the max() function

max(list)

The max() function will read through the contents of the specified iterable, such as the list, and return the largest value. A valueError occurs if an empty value or list is passed to the max() function.


Example
In this example, we will identify the greatest number in the given list.

my_list = [90,67,8,45,23,46,32]
find_max = max(my_list)
print(find_max)


Output

90 will be returned as the highest value

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

239 Views