Python max() function returns the item with the highest value in an iterable object or largest of two or more arguments.
Find the largest item in an iterable object (List, tuple, etc)
max(iterable)
Or
Find the largest item between two or more objects
max(n1, n2, n3, ...)
Python max() function example
Simple example code how to use max() function. If the values are strings, an alphabetical comparison is done.
Get the largest item on a list
number = [3, 2, 8, 5, 10, 6]
res = max(number)
print("The largest number is:", res)
Output:
Finding the maximum of 3 integer variables
var1 = 40
var2 = 80
var3 = 20
res = max(var1, var2, var3)
print(res)
Output: 80
Get the largest string in a list
languages = ["Python", "C++", "Java", "JavaScript"]
res = max(languages)
print("The largest string is:", res)
Output: The largest string is: Python
Do comment if you have any doubts or suggestions on this Python function topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.