Join Regular Classroom : Visit ClassroomTech

Python Tuple – max() Method

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(tuple)

Don’t know what is len method in Python Tuple? Read: len() method in Python Tuple

Example 1:

# Python program to understand max() method in tuple
# 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 tuple is 98. Hence it returned 98.

Example 2:

# Python program to understand max() method in tuple
# 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() method in tuple
# 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