max() function in Python List

It is an inbuilt function in python that returns the max value among all the numbers, if string is involved then alphabetical character with the highest ascii value is returned.

Syntax:

max(list)

Example 1:

# Python program to understand max() function in list
# www.codewindow.in

s = [85, 55, 47, 98, 32, 65, 62, 54] 
x = max(s)
print(x)

Output:

98

Explanation:

Here the largest number in the list is 98. Hence it returned 98.

Example 2:

# Python program to understand max() function in list
# www.codewindow.in

s = ["a", "k", "z", "h"] 
x = max(s)
print(x)

Output:

z

Explanation:

Here the ascii value of “z” is the highest among all other elements. Hence it returned “z”.

Example 3:

# Python program to understand max() function in list
# www.codewindow.in

s = ["Code", "and", "hustle"] 
x = max(s)
print(x)

Output:

hustle

Explanation:

Here the ascii value of “h” in “hustle” is the highest among all other characters. Hence it returned “hustle”.


You Missed

Also Checkout