Find Maximum of Items in a Tuple

To find maximum of items in a Tuple in Python, use max() builtin function. We can also provide a key function for max() to transform the items and then find the maximum of those values.

Python max() builtin function

Examples

Maximum of Tuple of Integers

In the following program, we take a tuple x with integer values, and find the maximum item in this tuple.

Python Program

aTuple = (2, 5, 8, 1, 4, 3)
result = max(aTuple)
print('Maximum :', result)
Try Online

Output

Maximum : 8

Maximum of Tuple of Strings based on Length

Here key is length of the item. To find maximum of strings based on length, call max() function and send len() function as key parameter.

Python Program

aTuple = ('Tea', 'Banana', 'Pomegranate')
result = max(aTuple, key=len)
print('Maximum :', result)
Try Online

Output

Maximum : Pomegranate

Conclusion

In this Python Tutorial, we learned how to find the maximum of items in a Tuple in Python using max() function.